Skip to content

Unsloth Studio: link other Unsloth instances and serve their models as @name/model - #18310

Open
danielhanchen wants to merge 3 commits into
mainfrom
studio-linked-instances-backend
Open

danielhanchen wants to merge 3 commits into
mainfrom
studio-linked-instances-backend

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Linking another machine (a Colab session, WSL, a PC on the LAN) makes its models usable through this machine's API as @name/model, with one key.

Split from #12092 and #12388 (by @LeoBorcherding), rebased on current main. The security changes from #12388 are part of this PR, so no merge state ever forwards tool requests to a linked machine.

What it does

  • Owner-only registry of linked Unsloth instances (/api/linked-instances): add, edit, remove, test, status, hardware info. The remote's API key is stored encrypted next to the other provider credentials.
  • /v1/chat/completions, /v1/completions, /v1/responses, /v1/messages (+ count_tokens), /v1/embeddings and /v1/images/generations forward an @name/model id to that instance. /v1/models lists their models after the local ones, including model aliases.
  • Forwarded requests show up in the API monitor with token counts and first-token time.
  • Image URLs from a linked instance name its own host, so they are fetched as base64 and served from this machine's gallery.

Safety

  • Tools are off per linked instance until the owner allows them. Tool fields are removed from the request, enable_tools: false is sent, and an X-Unsloth-Linked-Tools-Off header makes the remote hard-disable tools for that request (a body flag alone loses to a remote launched with --enable-tools). Changing an instance's address turns tools off again.
  • Relayed replies keep only JSON, SSE and media types. Anything else goes out as an attachment with nosniff and a sandbox CSP.
  • Plain http is accepted only for loopback and private LAN hosts, and checked again on every request, so a DNS change cannot send the key in the clear. Environment proxies are ignored for these requests.
  • A forwarded request carries a hop header, so a remote never forwards again (A links B links A).
  • Managed accounts and keyless callers cannot use linked models.

Tests

  • tests/test_linked_instances.py (48 tests) plus the account matrix entries for the new routes.
  • Live check: a real Studio linked to a recording fake remote. With tools not allowed, the remote received enable_tools: false, no other tool fields and the tools-off header. With tools allowed, the fields arrived unchanged. On Unsloth Studio / Desktop: link other Unsloth instances and serve their models through one API as @name/model #12092's code, both cases forwarded enable_tools: true and permission_mode: "off".
  • The backend tests that touch the changed routes (30 files, 1835 tests) give the same failure set on this branch and on main (21 failures; they need packages this test environment did not have, such as PyTorch).

Follow-ups stacked on this: #18311 (Settings UI), then #18312 (API page cards) and #18332 (Images on a linked machine).

…model

Owner-only registry of linked Unsloth Studio instances. /v1 chat, completions,
responses, messages, embeddings and image generation forward an @name/model id
to that instance with its stored key; /v1/models lists their models.

Tools stay off on a linked instance until the owner allows them: tool fields
are stripped, enable_tools is sent as false, and a header makes the remote
hard-disable tools for the request. Relayed replies keep only JSON, SSE and
media types. Plain http is allowed only to loopback and LAN hosts, checked
again on every request.

Split from #12092 and #12388.

Co-authored-by: LeoBorcherding <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-18T11:50:18.105918Z
We couldn’t complete this review. Comment @codex review to try again.
dd5ffd1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen danielhanchen added new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard labels Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant