Skip to content

Studio: one-click OS sandbox setup, faster sandbox checks, isolated cmd fallback on Windows - #12272

Merged
danielhanchen merged 59 commits into
studio-sandbox-settingsfrom
studio-sandbox-v2
Oct 5, 2026
Merged

danielhanchen merged 59 commits into
studio-sandbox-settingsfrom
studio-sandbox-v2

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Stacked on #12215 (Settings > Sandbox). Merge that first; this then retargets to main.

Python and Terminal already use bubblewrap (Linux), Seatbelt (macOS) or MXC (Windows) automatically when the live check passes. What was missing:

  • nothing ever offered to install or set up the OS sandbox;
  • "Run automatically" ran without prompts even when there was no OS sandbox behind it;
  • the first tool call paid for the sandbox check;
  • on Windows, the Terminal stayed unisolated on Git Bash when cmd.exe could have run isolated.

This PR fixes all four. The permission level names and stored values stay as they are on main (Ask for approval, Approve for me, Run automatically, Full access; ask, auto, off, full).

Setting up the sandbox

Picking Run automatically on a computer whose OS sandbox does not work opens a dialog with the reason. It offers these actions, in order:

  • Install sandbox (Linux) or Set up Windows sandbox;
  • Copy command;
  • Use it anyway (risky calls will ask);
  • Cancel.

Picking the level never starts anything by itself; only the button does, and picking it again later reopens the dialog. The menu row shows "OS sandbox not available" while that is the case.

Settings > Sandbox shows the same setup as one "OS sandbox" row: a one-line reason, the command, and the button where one is allowed. The Python and Terminal rows then show only their badge, so the long probe text is no longer repeated three times.

Settings > Sandbox on Windows shows the same idea in its own section: the runtime row, then the switch, then Prepare this PC. While that section says what to do, the Python and Terminal rows keep only their badge.

Real staging runners, Studio installed from this branch, real clicks and the real setup button (no stubbed routes). Each strip reads left to right:

Ubuntu 24.04 (bubblewrap missing): tab, dialog from picking Run automatically, after Install sandbox, tab after.

Ubuntu 24.04: Sandbox tab, setup dialog, setup done, tab after

Ubuntu 22.04 (bubblewrap removed first): tab, dialog, tab after.

Ubuntu 22.04: Sandbox tab, setup dialog, tab after

macOS 15 (Seatbelt works): tab, menu, Run automatically applied with no dialog.

macOS 15: Sandbox tab on Seatbelt, permission menu, Run automatically applied

Windows Server 2025 (MXC runtime removed first): Install runtime row, after the runtime install, dialog with consent, tab after (Python on MXC, Terminal on isolated cmd, administrator setup done).

Windows Server 2025: runtime row, switch after install, setup dialog, tab after

OS What the button does
Linux Installs bubblewrap with the host's package manager (apt, dnf, pacman, zypper, apk). On Ubuntu 24.04 style hosts where AppArmor blocks unprivileged user namespaces, it also loads Ubuntu's own bwrap-userns-restrict profile. These are the same packages and profile install.sh already names, plus apt-get update and non-interactive flags. Elevation: sudo -n when sudo needs no password, else one pkexec prompt on the desktop, else the command to run in a terminal. It never changes the sysctl, never makes bwrap setuid, and never runs Unsloth as root.
macOS Nothing to install: Seatbelt is built in. Only the reason is shown if the check fails.
Windows Installs the MXC runtime if missing, turns on the opt-in only with the consent box ticked (same disclosure as #12215), then runs the existing Prepare this PC step (UAC). The runtime-only install in Settings > Sandbox comes from #12215 and shares this job. Windows that cannot run MXC (not x64, or older than build 26100) is offered nothing.

Who can start a setup:

The endpoint takes a fixed operation name, never a command. Everyone else gets the command to copy, and the dialog says why there is no button: another account, another computer, or no way to ask for the password here.

Run automatically without an OS sandbox

In a streaming UI chat, the only place a prompt can be answered, Run automatically now asks before a risky Python or Terminal call when that tool has no working OS sandbox. Risky means the same high-risk check Approve for me uses. Everything else is unchanged:

  • other tools and routine calls run without asking;
  • API clients that never prompted still do not;
  • Full access keeps main's owner-only rule.

This holds for saved chats too (the resumable runs Studio uses for normal chats) and for every local engine: llama.cpp, safetensors and vLLM/SGLang.

When the prompt is skipped because the cached answer says the tool is isolated, that call launches in strict mode. A sandbox that stopped working since then refuses the call with the setup command, instead of running it under software safeguards.

Speed

  • Picking Run automatically. When the sandbox is already known to work, the pick applies at once instead of waiting on a fresh check.

  • Startup check. The sandbox check runs in the background when the server starts (Linux and macOS), so the first Python or Terminal call does not wait for it. Windows keeps it lazy: with the MXC opt-in on, a startup check would start a container and apply the read grants at every launch.

  • Stale passes. A passing probe older than its 15 minute lifetime keeps being used for up to an hour while one background re-check runs, instead of making a tool call wait. A failing probe is cached for 60 s and never served stale, and a launch failure clears the cache at once.

  • Gate and dialog caches. The Run automatically gate reads a per-tool answer that is refreshed in the background every 60 s, and never waits on a probe. The browser caches the capability read for 30 s, and drops it when a setup finishes.

Windows Terminal

When Git Bash fails the MXC check for any reason and cmd.exe passes, the Terminal now runs isolated on cmd. Before, only the Git Bash namespace error switched it, and on a freshly prepared host Git Bash fails without that signature, so the Terminal stayed unisolated on bash. Full access and UNSLOTH_MXC_TERMINAL_CMD=0 still keep the host shell.

Other changes

  • Elevated setup steps run by absolute root-owned path from /usr/sbin, /usr/bin, /sbin or /bin, with a fixed environment (no inherited PATH, LD_* or PYTHON*), so nothing a tool call writes into Studio's PATH can run as root.
  • The passwordless sudo check only runs for the owner on this computer (cached for 10 minutes, checked again right before a setup), never on another account's read.
  • The Windows setup command names this install's paths, so only the owner sees it. It is written for PowerShell (one & '...' line per step), which Windows PowerShell 5.1 can run.
  • The setup and Sandbox tab text is translated in all 12 locales.

Results

Through the UI on the latest head (the screenshots above): on ubuntu-24.04, ubuntu-22.04 and Windows Server 2025 the setup button ended with "The OS sandbox is ready. Run automatically is on." and the capability read then reported Python and Terminal OS-isolated (bubblewrap, bubblewrap, MXC). macOS needed no setup.

Staging runners, the real routes, setup job, probes and tools, owner session; passwordless sudo on Linux runners, the already elevated branch on Windows:

Runner Before setup Setup (Install button) After
ubuntu-24.04, bwrap missing, AppArmor restricts user namespaces Software safeguards; Run automatically asks before a risky Python or Terminal call apt-get update, bubblewrap, apparmor-profiles, profile loaded: succeeded in 108 s Python and Terminal on bubblewrap; Run automatically no longer asks
ubuntu-22.04, bwrap removed Same bubblewrap: succeeded in 15 s Same as above
macos-15 Seatbelt already on Nothing offered Unchanged
windows-latest (Server 2025), MXC runtime not installed Software safeguards Consent, runtime install, Prepare this PC: succeeded in 360 s Python on MXC, Terminal on isolated cmd, git --version runs isolated

On every leg a remote client got 403 for the setup and only the command from the capability read, and a second setup after success answered 409.

A second Windows Server 2025 check went through the same setup job end to end, four times on fresh runners. Each time:

  • Before setup: Python was not isolated, and Run automatically asked before a risky call.
  • Install runtime alone: the runtime installed in about 2 s, but MXC still did not run. This Windows build has no BaseContainer, so the consent and Prepare this PC are needed.
  • Full setup: succeeded in 385 to 465 s.
  • After setup: Python and Terminal passed the live MXC checks, and Run automatically stopped asking.
  • Isolation:
    • A Python call ran inside MXC.
    • Writes outside the working folder through _io.FileIO and nt.open, below the Python shim, were refused by MXC with PermissionError. The host files were unchanged.
    • Reading a file in the user's home folder was refused.

test_mxc_native_windows.py on that runner: 13 passed, 1 skipped (no second writable volume). Two Terminal probe tests fail the same way on the merge base, so they are not from this PR:

  • Windows PowerShell 5.1 cannot find Set-Content inside MXC; PowerShell 7 and cmd pass.
  • Git Bash exits 0xC0000142 with no output, so it gets the generic reason instead of the named one.

Latency, median ms over 3 interleaved rounds, same runner (Full access = no OS sandbox):

Runner Sandbox check First Python call, before / after the startup check Warm Python call, sandbox / Full access Warm Terminal call, sandbox / Full access
ubuntu-24.04 121 188 / 73 50 / 42 34 / 10
ubuntu-22.04 163 294 / 133 93 / 45 43 / 12
macos-15 166 255 / 110 85 / 50 43 / 15
windows-latest (MXC) 576 786 (no startup check on Windows) 194 / 62 224 / 52

Local, after merging the latest main:

  • Backend sandbox, permission, MXC, settings, account and route suites: 6498 passed. The 18 failures also fail on the parent branch on this host (CUDA and optional dependency tests).
  • Frontend: typecheck, i18n:check:strict and the node tests (65) pass.

Not covered

  • Twice, at the end of a full UI run on macos-15, a forced Seatbelt re-check timed out after 30 s while the tab still showed Seatbelt. Two targeted runs did not reproduce it on either branch: 47 forced reads (idle, with a browser, three at once, and every 20 s for 6 minutes on the capability route) all passed in under 0.8 s. I read it as runner load, not this PR.

  • A real polkit dialog on a Linux desktop and a real UAC prompt (runners have passwordless sudo and run elevated).

  • Package paths other than apt on real hosts (dnf, pacman, zypper and apk are unit tested only), WSL, Windows on ARM64 (offered no runtime install, only a note) and MXC's BaseContainer tier.

  • The state after a real Windows reboot (the null device step has to be prepared again; the dialog offers it).

Screenshots

BEFORE is #12215 (8ce5b91, the parent this stacks on), AFTER is this branch (428a6ae); two isolated installs on a Linux host whose user namespaces are restricted.

Settings > Sandbox: the per-tool probe text gives way to one OS sandbox row with a short reason and the command.

Sandbox tab before and after: raw bubblewrap probe text per tool, then one OS sandbox row with the AppArmor reason and the command

The permission menu now says when the sandbox is not available:

Permission menu before and after: Run automatically gains the note OS sandbox not available

Picking Run automatically: before, it switched straight to it; after, the setup dialog opens with the reason, the command (this host cannot ask for a password, so no Install button) and Use it anyway, and the mode stays as it was.

Picking Run automatically before and after: mode switches silently, then the setup dialog with reason and command

Recording of that pick on this branch:

Recording: open the permission menu, pick Run automatically, the setup dialog checks the sandbox and shows the command

The real setup on staging runners, one step per frame (the same runs as the strips above): Ubuntu 24.04 with Install sandbox, and Windows Server 2025 from a missing runtime to both tools on MXC.

Ubuntu 24.04 walkthrough: no sandbox, menu note, setup dialog, installing, done, both tools on bubblewrap

Windows Server 2025 walkthrough: Install runtime, switch appears, setup dialog with consent, done, both tools on MXC

…picker, and show setup in Settings > Sandbox

Ask every time, Auto-approve, Full access in sandbox and Bypass permissions replace the old labels; the stored values are unchanged and the labels move to i18n in all 12 locales. Picking Full access in sandbox on a computer without a working OS sandbox opens a setup dialog (install, copy the command, or use it anyway) instead of switching. Settings > Sandbox shows the install command and a Linux install row, and can install the Windows MXC runtime.
…ly when no OS sandbox is on, and warm the sandbox check at startup

One shared approval decision replaces the three loop copies. Under permission mode off the route
arms the confirm gate only on a stream carrying the control frames, and the loop then asks only
for a high-risk python or terminal call whose cached capability is not OS isolated. The cached
answer never blocks on a probe; a startup warm-up and a stale-while-revalidate probe cache keep
the first call and the 15 minute recheck off the request path. GET /api/sandbox/capability
reports the cached answer to any signed-in user.
…and status reads, and use the new mode names in backend messages
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 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-05T10:52:55.602834Z 515edfd Manual request
🔒 Security Review ✅ Completed 2026-09-29T10:38:17.634215Z 334171c Manual request

Security findings

Finding details are still loading. Check the individual review comments.

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

… asks for Windows consent only when needed, shows why a setup failed, and installs the Windows runtime without an administrator prompt
…, pin every elevated setup step, and check the sandbox before answering after setup
… a running setup on the prepare route, give PowerShell a command it can run, and translate the dictation menu label
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 8623f4ad68

ℹ️ 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 Sep 29, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 29, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Brings in the Settings > Sandbox runtime install. The tab keeps this
branch's single setup job tracker; the runtime row reads its windows-runtime
runs. The runtime-only install now also works from a remote owner browser
(it has no administrator prompt), the chained setup stays local-only, and
Windows that cannot run MXC (not x64, or older than build 26100) is offered
no setup at all.
…ed engines

- Durable chat runs persisted confirm_tool_calls=False for Run automatically,
  which the replay read as an explicit opt-out, so the ask-before-risky-calls
  check never armed in normal Studio chats. Drop the forced value when saving.
- The vLLM/SGLang tool loop now arms the same check as the other loops.
- The picker hook and the setup dialog apply only their newest capability
  read, so a slow older answer cannot undo a newer one.
- Saving a sandbox setting or finishing Prepare this PC drops the cached
  capability the chat picker reads.
- pkexec setup on Alpine runs BusyBox as its sh applet.
… work

The pick waited for a forced live probe even when the cached answer said the
OS sandbox works, so on a slow host the menu looked unresponsive for seconds.
The backend checks isolation on every call either way.
While the Windows section shows what to do (install the runtime, turn the
sandbox on, prepare this PC), the Python and Terminal rows keep only their
badge, and on Windows they never repeat the generic MXC remediation text.
The setup reason says the PC needs its administrator step instead of naming
MXC's internal step ids.
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
@danielhanchen danielhanchen self-assigned this Oct 5, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 408207e644

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 515edfde98

ℹ️ 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 added a commit to Datta0/unsloth-staging-3 that referenced this pull request Oct 5, 2026
@danielhanchen
danielhanchen merged commit a249b3e into studio-sandbox-settings Oct 5, 2026
@danielhanchen
danielhanchen deleted the studio-sandbox-v2 branch October 5, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects UI# codex-converged# important# new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard >3000#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant