Skip to content

Studio: add capability-aware OS isolation for local tools - #10285

Closed
Etherll wants to merge 132 commits into
unslothai:mainfrom
Etherll:codex/studio-minimal-os-sandbox-20260903-194724Z
Closed

Etherll wants to merge 132 commits into
unslothai:mainfrom
Etherll:codex/studio-minimal-os-sandbox-20260903-194724Z

Conversation

@Etherll

@Etherll Etherll commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add capability-aware isolation for Studio's local Python and Terminal tools. OS isolation is the default, unavailable backends fail closed, and users can explicitly choose session-only Limited execution when a qualified launch path is unavailable. Full access remains a separate option with its own warning.

The implementation now includes Linux Bubblewrap, macOS Seatbelt Preview, Windows restricted-token Limited execution, and an experimental Windows LPAC Python runtime. Windows LPAC qualification is not complete, so its Required path remains blocked.

Motivation

Replace the approach from #7101 without treating software checks as an OS sandbox or making compatibility failures silently reduce protection. In particular, preserve private Unix sockets for Linux multiprocessing and resource sharing while keeping existing host sockets out of the sandbox.

Users should see the protection actually used by a tool launch, not a label inferred from model arguments or their currently selected settings.

Changes

Shared launch and permission handling

a

  • Route production Python and Terminal execution through prepare_tool_launch() and spawn_prepared_launch() in studio/backend/core/inference/os_sandbox.py and tools.py.
  • Keep streaming, resource limits, descriptor closure, timeout, cancellation, and cleanup in the launch path. Backend-specific lifecycle limitations remain explicit.
  • Default to Required OS isolation. Preparation, validation, or spawn failure does not trigger a host fallback or automatically replay the command.
  • Retain Process Guard, environment sanitization, command analysis, and workdir checks as defense in depth, not as substitutes for OS isolation.
  • Bind short-lived Limited grants to the authenticated UI session and capability generation. Stale or cancelled requests cannot restore obsolete consent.
  • Emit execution records only after a successful spawn. Live tool cards use backend-owned records; model/provider arguments cannot supply protection labels.
  • Show capability details, limitations, retained safeguards, and actionable failure reasons beside the existing tool-permission control.

Linux Bubblewrap

  • Confine persistent writes to the session workdir and expose required OS/interpreter runtime paths read-only.
  • Use private namespaces, /proc, /tmp, /dev/shm, minimal devices, and seccomp restrictions.
  • Validate runtime roots during preparation. Both scanners reject existing Unix sockets, FIFOs, and device nodes, and trusted-scanner failures fail closed.
  • Mask foreign nested mounts after the final runtime bind, including interpreter roots beneath host /tmp.
  • Preserve private AF_UNIX communication and standard-library multiprocessing/resource sharing instead of denying all Unix sockets.
  • Run live capability probes. Native Linux can report Protected; WSL2, containers, and Colab can report Preview only when their environment-specific probes pass.

macOS Seatbelt Preview

  • Generate a deny-default profile around the selected interpreter and required runtime paths using the root-owned sandbox-exec.
  • Restrict filesystem access, deny IP networking and sensitive host IPC/services, and permit private temporary Unix sockets.
  • Require a live policy probe before availability.
  • Disclose that SBPL/sandbox-exec is deprecated and undocumented for third-party use, and that detached setsid()/double-fork descendant cleanup remains unverified. Ordinary cleanup uses the existing process-group path.

Windows compatibility and experimental LPAC

  • Add explicit Limited execution under a restricted token and resource-limited Job Object, with tracked filesystem grants and cleanup ownership.
  • Coordinate concurrent ACL changes and cleanup under a cross-process ledger. Refuse mutation when the ledger cannot be acquired, and remove only grants owned by the invocation.
  • Disclose Limited's remaining exposure, including unrestricted networking, host-dependent readability, Everyone-writable objects, and named-pipe compatibility restrictions where observed. Restricted-token Limited is not LPAC qualification.
  • Add an experimental native Python bootstrap for matching CPython 3.11, 3.12, and 3.13 x64 release builds. This is a build registry, not a qualified support matrix.
  • Integrate protected runtime/package snapshots, bounded preparation workers, a private Winsock catalog, a clean-entry handshake, post-drop retained-authority checks, and invocation cleanup.
  • Add a narrowly admitted Pillow activation-context adapter using a pinned Microsoft Detours build, with source/build identity checks and offline companion packaging. No build or download runs at tool-execution time.
  • Keep Python and Terminal qualification separate. The intended Windows Python profile permits imports and threads but only one workload process; it does not promise Linux-style multiprocessing compatibility.
  • Keep Required LPAC unavailable until the complete selected-runtime probe passes. Retained IPC proof and Terminal child-launch compatibility remain unfinished.

Network policy

  • Deny network access by default for OS-isolated tools.
  • Add an explicit HTTPS-host allowlist path through a local proxy on supported Linux/macOS backends. Queued requests cannot widen the user's current consent.
  • Do not offer that allowlist on Windows. Limited and Full execution do not gain OS-level network confinement from this setting.

How to test

From studio/backend:

python -m pytest -q \
  tests/test_os_sandbox.py \
  tests/test_tool_isolation_api.py \
  tests/test_network_allowlist_tools.py \
  tests/test_network_proxy.py \
  tests/test_tool_output_streaming.py \
  tests/test_studio_tool_loop.py \
  tests/test_bypass_permissions.py

Run native platform tests on the matching host. Skips do not qualify a backend:

python -m pytest -q -s tests/test_macos_seatbelt.py
python -m pytest -q -s tests/test_windows_restricted_token.py tests/test_windows_lpac.py

The experimental Windows bootstrap build prerequisites and installed-runtime tests are documented in studio/windows_sandbox_runtime/README.md.

From studio/frontend:

npm run typecheck
node --experimental-strip-types --test --test-concurrency=2 "tests/**/*.test.ts"
npm run build

Manually verify Required blocking, Limited consent and cancellation, grant loss on refresh, separate Full confirmation, and actual Python/Terminal output labels. A preparation failure must show no successful execution label.

Notes for reviewers

The trust boundary excludes hostile concurrent host mutation. A read-only runtime bind is not an immutable snapshot, and host-side changes can remain visible through it. Preparation revalidation does not eliminate that race.

This is not protection against kernel exploits, host administrators, malicious hypervisors, or every denial-of-service attack. Preview and Limited limitations are part of the product contract, not equivalent to Protected isolation.

MCP execution is outside the security claim. SRT, Microsandbox, microVMs, and a general broker/service architecture are not included. Future isolation backends can extend the existing backend probe/preparation interface without replacing the Python and Terminal call sites.

Related

Replaces the approach from #7101.

@danielhanchen

Copy link
Copy Markdown
Member

Opened #10526, which takes this PR's Linux bubblewrap policy and its Seatbelt profile as the starting point and drops the Windows work.

The argv shape, the parent-directory read grants, the synthesised /etc/passwd, the dual /private spellings, the ancestor file-read-metadata rules and the optional literals all come from here, and the keychain escape you closed by keeping com.apple.SecurityServer out of the mach-lookup set is kept out, with a regression test. Granting parent directories rather than enumerating individual shared libraries is the right call and I took it: #10441 went the other way and had to raise its read-root cap from 128 to 1024.

The reason I did not simply advance this branch is size. 67,308 lines across 199 files, and 72 percent of it is Windows: 28,359 lines of LPAC and restricted-token policy plus 20,081 lines of Detours C shim and its tests. That is the highest-consequence, hardest-to-review code category there is, and it would become ours to maintain. Linux and macOS together are a few thousand lines, and the macOS backend here is 700 lines of which all 700 are a test file.

So the split I would like is: Linux and macOS through #10526, and Windows through #10441's pinned upstream SRT once its srt-win wfp verify stops timing out on windows-2022. That leaves nobody hand-maintaining an AppContainer policy or a C API-hooking shim.

Two things from here that #10526 does not carry, and I would take either as a follow-up if you think they matter: the editable-install path parsing, and the seccomp userns fallback for bwrap older than 0.8.0 is present but only lightly tested.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants