Skip to content

Studio: retire the seeded password on Desktop and keep API callers on Sandbox High - #14422

Merged
danielhanchen merged 3 commits into
mainfrom
studio-loopback-bootstrap-hardening
Oct 21, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-loopback-bootstrap-hardening

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Hardening from a security review of the Studio tool sandbox. Nothing changes for Desktop sign-in, the first-run password change in the web UI or Colab, or notebooks.

Problem 1: the seeded owner password stays in the page on Desktop. While the default unsloth password is still pending a change, index.html carries it for a direct loopback client so the first-run screen can fill it in. A Desktop backend never retires it: the shell signs in through /api/auth/desktop-login, which answers must_change_password = False, so the pending state can last forever. Tool code runs in a jail that shares the host network on purpose (tools download models), so it reaches the loopback port like a local browser and can read that password.

Change. A Desktop-owned backend no longer injects the seeded password, and a successful desktop-login clears it from memory. The Tauri shell loads its own bundled frontend and signs in with its own secret; the only reader of the injected value is the change-password form, which the shell skips. The web UI, unsloth studio and Colab first-run autofill are unchanged.

  • Visible difference: a Desktop user who opens http://127.0.0.1:<port> in an ordinary browser before ever setting a password now sees a "Current password" field instead of an autofilled one (the password is in .bootstrap_password, as before). After the password is set in Desktop, browser login is unchanged.

Problem 2: API callers can still pick Sandbox Low. #14345 keeps API-key and keyless callers out of Full access, bypass_permissions and disable_sandbox, but sandbox_level: "low" (Python and Terminal on software safeguards only, no OS sandbox) was not part of that check.

Change. require_tool_access also refuses sandbox_level: "low" for API-key and keyless callers, with the same 400 and the same UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1 opt-in. The default is high, the UI (session login) keeps Sandbox Low, and one check covers /v1/chat/completions, /v1/responses, /v1/messages and durable chat runs.

Both changes are pure checks; nothing is stored, so repeating them is a no-op.

Tests. test_desktop_bootstrap_retired.py and test_api_key_sandbox_level.py: 13 of 19 fail on main, all 19 pass here. The 90 existing modules that exercise these files give the same result on both sides (one test, test_desktop_auth.py::test_health_response_reports_desktop_capability_fields, already fails on main).

Before / after. A first launch with the Desktop owner variables set, opened in a plain browser tab. Before, the page carries the seeded password and the setup form fills it in silently (no "Current password" field); after, the page no longer contains it and the form asks for the current password. The Desktop app itself signs in through /api/auth/desktop-login and does not use this page.

Desktop bootstrap before and after

… Sandbox High

A desktop-owned backend no longer embeds the seeded admin password in
index.html. The desktop shell signs in with its own secret and never reads
the page credential, so serving it only exposed it to other local processes
on the loopback port. A verified desktop-login also clears the in-memory
bootstrap password, the same way logout and change-password already do.
Web installs (unsloth studio, Colab) keep the first-run autofill.

API-key and keyless callers asking for sandbox_level "low" (Python and
Terminal without the OS sandbox) are now refused with a 400, matching how
full access is already refused for them. UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1
restores it, and Unsloth UI and Desktop sessions are unchanged.
@danielhanchen danielhanchen self-assigned this Oct 21, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T02:21:07.464306Z 385711c Manual request
🔒 Security Review ✅ Completed 2026-10-21T02:00:20.435433Z 428448e Manual request
ℹ️ 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

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 428448e022

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 428448e022

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/backend/routes/auth.py Outdated
Comment on lines +602 to +604
# The shell owns this backend and never uses the seeded password: stop serving it to the page.
try:
request.app.state.bootstrap_password = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve bootstrap autofill on ownerless backends

When the Desktop app attaches to an existing terminal-started, same-root backend, backend_desktop_auth_status explicitly treats that ownerless backend as adoptable and the shell posts its valid desktop secret here. This unconditional clear then removes the bootstrap credential from subsequent ordinary browser pages even though the backend is not Desktop-owned and the default password still requires changing, regressing the web first-run autofill. Guard this clear by Desktop ownership, as _inject_bootstrap already does.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 385711c: the clear now only runs when the backend is Desktop-owned; an ownerless backend the shell attached to keeps the web first-run autofill (test added).

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 385711caa6

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 21, 2026
[skip ci]
@danielhanchen
danielhanchen merged commit fd8a88d into main Oct 21, 2026
@danielhanchen
danielhanchen deleted the studio-loopback-bootstrap-hardening branch October 21, 2026 04:40
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 25, 2026
…ox (unslothai#14757)

## Problem

unslothai#14345 and unslothai#14422 set the rule that an API key (or keyless API access)
never runs Python or Terminal without the OS sandbox unless the server
sets `UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1`: Full access,
`bypass_permissions`, `disable_sandbox` and `sandbox_level: "low"` are
all refused for API callers.

The tool approval path was not part of that rule. In `auto` and `ask`
modes a call that names a host path outside the sandbox roots parks for
confirmation, and an approved one launches with software safeguards only
(`_prepare_tool_launch`, fault `user_approved_host_access`). `POST
/api/inference/tool-confirm` accepts an approval from any authenticated
caller, API keys included, and the request that started the run receives
the approval id in its own stream. So an API caller could approve its
own parked host-path call and get the unsandboxed launch the other
checks refuse.

A second gap made the launch side unable to tell: for an owner-scoped
API key, `account_tool_stream` ran the tool thread without rebinding the
account, so the thread lost the "admitted by an API key" flag.

## Change

- `/tool-confirm`: an `allow` from an API-key or keyless caller for a
parked call that would reach host paths gets 403, naming the env opt-in.
`deny` is accepted from everyone, and approving a call that stays in the
sandbox is unchanged.
- The three tool loops (`studio_tool_loop`, `llama_cpp`,
`safetensors_agentic`) flag a parked call as host access when it is
registered, using the same `_reaches_host_paths` check the executor
applies before honouring an approval (`approval_grants_host_access`).
The flag is set before the approval id is sent to the client.
- Launch side, independent of who approved: `_prepare_tool_launch`
ignores an approval for a call that came from an API-key request and
keeps it in the OS sandbox in `required` mode, so a sandbox that is
unavailable refuses instead of falling back to software safeguards. The
Windows cmd Terminal path applies the same check.
- `account_tool_stream` now rebinds the account for owner API-key
requests too, so the tool thread sees the same API-key flag the request
had (this also makes the existing `require_tool_access` check inside
`execute_tool` effective for owner keys).
- `UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1` restores the previous
behaviour for API callers. Unsloth UI and Desktop sessions are
unchanged.

## Tests

New `studio/backend/tests/test_api_key_tool_confirm.py` drives each of
the three tool loops end to end with a real approval slot, the real
`/tool-confirm` route (API-key auth faked as in
`test_api_key_sandbox_level.py`) and the real `_prepare_tool_launch`
decision (OS sandbox stubbed):

| case | main | this PR |
|---|---|---|
| API key approves a host-path call | 200, launches with software
safeguards | 403, call does not run |
| UI approves a host-path call from an API-key request | software
safeguards | OS sandbox, `required` |
| API key with `UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1` | software
safeguards | software safeguards |
| UI session approves its own host-path call | software safeguards |
software safeguards |
| API key denies | 200, not run | 200, not run |
| API key approves a sandboxed call (`ask` mode) | 200, OS sandbox |
200, OS sandbox |

14 of the 26 new tests fail on main and all 26 pass on this branch.

The 25 existing studio backend test files that touch tool approvals,
`host_access_approved`, the API Full access opt-in, `sandbox_level` or
`_prepare_tool_launch`, plus the new file (CPU, Linux): 4334 passed on
this branch and 4320 on main. The same 36 tests fail on both: the MCP
tests in `test_account_tool_isolation.py`, plus tests in
`test_llama_admission_compat_matrix.py`, `test_mcp_image.py`,
`test_llama_cpp_tool_loop.py::test_web_search_keeps_to_the_requested_domains`
and the Terminal cases of `test_tool_sandbox_wiring.py`. The only other
difference is the 14 new tests, which fail on main.

## Not covered

- A project folder the owner picked keeps running with software
safeguards for every call in `auto`, approved or not. That is unchanged
here, for API callers too.
- When the OS sandbox is unavailable, `auto` falls back to software
safeguards for calls that never park. That is unchanged too. Only the
approved host-path call from an API key is now refused.
- Tested on Linux with the OS sandbox stubbed. No live backend run, and
the Windows and macOS sandbox backends were not exercised.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Nov 5, 2026
…allowlist (#16674)

Fixes #16625 (the host
allowlist part)

## Problem

Python tool code that reaches a host outside the built in allowlist (for
example `requests.get("https://example.com/")`) is flagged as risky, so
in **Ask for approval** and **Approve for me** the user gets an approval
prompt. Clicking Approve did nothing: `_python_exec` re-ran the same
static check and refused the call with `Blocked: host not in sandbox
allowlist`. The only way to reach such a host was **Full access**, which
also turns off every file restriction. That is exactly the "soften the
network while keeping file access strict" gap from the issue.

Measured on main (Linux, software safeguards):

| Python code | asks first | approved | result |
|---|---|---|---|
| `urlopen("https://example.com/")` | yes | no | `Blocked: host not in
sandbox allowlist` |
| `urlopen("https://example.com/")` | yes | yes | `Blocked: host not in
sandbox allowlist` |

## Fix

`_check_code_safety` takes `host_approved`; when set it drops only the
`untrusted_host_blocked` findings. `_python_exec` passes it for a call
the user approved, the same way an approved `rm` is already let through
in `_bash_exec`.

- The allowlist is advisory today: every sandbox backend reports
`unrestricted_network` (see #13345), so this changes no boundary.
- Cloud-metadata hosts, uploads, non-literal destinations and every
other static check stay blocked, approved or not.
- File isolation is unchanged: the call still runs in the OS sandbox
unless it names host paths, which was already the rule for approved
calls.
- API-key requests keep the allowlist even after an approval, matching
#14345 / #14422.
- Run automatically and unapproved calls behave exactly as before. No UI
change.
- A remembered "Always allow" for Python in a chat counts as an approval
here, the same way it already does for host file access.

After the fix:

| Python code | approved | result |
|---|---|---|
| `urlopen("https://example.com/")` | no | `Blocked: host not in sandbox
allowlist` (unchanged) |
| `urlopen("https://example.com/")` | yes | `200` |
| `urlopen("http://169.254.169.254/...")` | yes | `Blocked:
cloud-metadata host` (unchanged) |
| `urlopen("https://pypi.org/simple/")` | either | `200` (unchanged) |

## Tests

`tests/test_sandbox_tools.py::TestApprovedHostLiftsOnlyTheAllowlist` (5
cases) fails on main and passes here: the approved host goes through,
metadata / upload / non-literal destinations stay blocked, and an
API-key caller is still refused.

Base vs head over the 11 test files that touch the changed code
(`test_sandbox_tools`, `test_tool_sandbox_*`,
`test_api_key_tool_confirm`, `test_approved_rm`,
`test_permission_mode*`, the tool loop tests,
`test_windows_cmd_terminal_profile`): base 6 failed / 4336 passed, head
1 failed / 4341 passed. The 5 new tests are the only change; the
remaining failure
(`test_llama_cpp_tool_loop.py::test_web_search_keeps_to_the_requested_domains`)
fails on main too.

Extra folders and per-tool allow rules from the issue are separate
features and are not part of this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant