Repository navigation
Conversation
The contract only, so the two backends can land against a stable shape. Three modes: auto (isolate if the host can, otherwise run exactly as today and label the result), required (refuse rather than run unisolated), and full (the existing bypass, unchanged). auto is the default and is the one mode that can never refuse. Windows and every other platform take the unavailable path, which is main's behaviour byte for byte.
Bubblewrap on Linux, Seatbelt on macOS, reached through the launch contract added in the previous commit. No Node, no vendored dependency, no npm, no network proxy. What the boundary covers, and it is deliberately narrow so the label can be true: no writes outside the session workdir, /tmp and /dev/shm; no reads of the user's home beyond the runtime paths the interpreter itself needs, so ~/.ssh, ~/.aws, ~/.config/gcloud and unrelated documents are gone; a fresh PID namespace; AF_VSOCK, io_uring and nested user namespaces denied. The network is NOT confined, on purpose. pip install, model downloads and API calls inside a tool call keep working, and a script that can still reach a secret can still send it. The record says network_policy=unrestricted rather than staying quiet, because the badge should not read as more than this is. The static analysis in tools.py remains the only thing standing between a tool call and an outbound secret. Availability is never inferred from a binary existing. The probe launches a real sandbox through the same prepare() the product uses and checks that its negative controls fail -- an installed bubblewrap on a host that denies user namespaces looks identical to a working one until you try it. Nothing that ran yesterday stops running. In auto on a host without a sandbox the planner hands back the argv, cwd, env and pre-exec it was given, unchanged; Windows and every other platform take that path unconditionally. Measured: win32, freebsd and an unavailable linux all come back byte identical, with no preexec_fn or pass_fds added on Windows and creationflags preserved. Verified in a privileged container where bubblewrap works, since this workspace host denies unprivileged user namespaces: 21 checks through the real prepare_tool_launch, covering all four credential canaries unreadable, writes to /etc /usr and / refused, the workdir and private tmp writable, network still reachable, host processes hidden, and numpy, Pillow and a multiprocessing spawn pool all working inside the jail. That container runs as root, so the unprivileged-userns path itself is still unproven; CI on a runner without the AppArmor restriction is what closes it. macOS is unproven entirely -- no Darwin kernel ever loaded the profile, and the two tests that would prove it are skipped rather than passed.
…ail, and hold macOS to the Linux read rule
…nd give pip a writable target
…itable workdir, and probe under no-new-privs
…name the macOS semaphore namespace
…cache mount points back through descriptors
…s, and bind a prefix's git helpers
…erial instead of masking the private
… mount on both backends
…ount table again for same-filesystem binds
…it off the kernel version
… the commands on PATH
… tests they carried
…ing the cache mount points
_linux_userns_blocked_by_apparmor forks unshare, and the remediation string that reaches it is built by every capability snapshot, so a host that cannot isolate paid an extra fork and exec on every single tool call. That is the common case on Ubuntu 23.10 and newer, which is the population this diagnosis exists for in the first place. The answer cannot change without an operator editing an AppArmor profile or a sysctl, and Studio is restarted for that, so cache it for the process. This also fixes test_the_process_unsloth_holds_still_lands_in_its_own_session, which counts the Popen calls one tool call makes and was seeing the stray unshare as a second launch. Leaving that assertion counting every Popen is deliberate: it is what catches the next stray subprocess on the launch path.
…re, and bind the macOS framework image
3e16c1c binds the workdir at the spelling the caller used as well as the canonical one, because a sandbox home reached through a symlink otherwise leaves Python unable to open its own argv. Only the canonical spelling got a --dir before --remount-ro /, so bwrap had to create the other mount point on a read-only root and died: bwrap: Can't mkdir /work/linked-session: Read-only file system That is exactly the case the second bind exists to serve, and the execution record had already recorded os_isolation = True by the time bwrap failed, so the call reported isolation it never got. Measured in a container with working user namespaces before and after. The test is argv-level so it runs everywhere, and it asserts both spellings appear among the --dir arguments ahead of the remount.
… unisolated sandbox_seccomp.filter_file() opens a temporary file, so a full disk makes it raise a plain OSError. Untyped, that reached the general "except Exception" in _prepare_tool_launch, which answers auto by running with software safeguards, so the call went ahead on the host with the boundary off. A tool call can fill the disk from inside its own workdir, which makes that reachable from the thing being sandboxed. Measured in a container with an injected ENOSPC before the fix: "the call ran on the host with the boundary silently off". SandboxBuildError is a sibling of WorkdirUnsafeError and is refused with it, for the same reason: the fallback belongs to a host that cannot isolate at all, and a host whose planner hit an OS error can. The backend is still installed and the probe still passes. Typing it this way rather than by asking the probe again is deliberate, and the type discrimination 5b21cf0 introduced is what makes it possible. A probe builds a real sandbox, so it fails under whatever transient the host is having, including the same ENOSPC it would be adjudicating. That was not hypothetical: this fix passed on its own, then regressed the moment it met d01f91f's forced re-probe, and the container caught it. Both directions stay covered: a backend that has genuinely gone still falls back in auto, and a build failure refuses in auto as well as in required.
No workflow installed bubblewrap, so the two tests that prove confinement have been skipping on every runner since the branch opened. Backend CI installs it now, and on 24.04, where the stock kernel.apparmor_restrict_unprivileged_userns=1 leaves bwrap present and still unable to build a sandbox, it applies the bwrap-userns-restrict profile. That is the same remediation this branch prints to users, so CI exercises the advice rather than sidestepping it with a sysctl. A runner where it still cannot work warns and skips instead of failing a PR for its host configuration. Three assertions that could not fail: - test_the_model_cache_shares_its_data_subdirectories_and_nothing_else built its expected value from _MODEL_CACHE_SUBDIRS, the constant under test, so both sides moved together. d0e3097 dropped "modules" from it and no test changed. Spelled out as a literal, plus an explicit check that "modules" is not shared. - test_home_is_unreadable_inside_the_sandbox ran "ls ~/.ssh" and asserted a non-zero exit, which any machine without a ~/.ssh passes whether or not anything is confined, and a CI runner is such a machine. It plants a canary and proves it readable on the host first, so the sandbox failing to read it means the sandbox. - test_runtime_read_paths_cover_the_interpreter_and_the_site_shim compared an unnormalized "tests/../core/inference" spelling against canonical entries, so it passed on its own file and failed in a full-suite run depending on which import loaded the module first. normpath.
…d workdir Five review items, each reproduced before it was fixed. An editable install's direct_url.json names the PROJECT root, and a checkout holds more than its packages: a .env, a credentialed .git/config, a key in test fixtures. Granting it recursively handed all of that to model-authored code that still has the network. Only the top-level packages and modules under the import root are granted now, with the import root itself listable but not readable on macOS so the interpreter can still find them. Bubblewrap 0.11 in a container: `import demo` works, reading the checkout's .env is ENOENT, and a listing shows only the package. The Linux runtime re-binds landed between the two workdir binds, so with a symlinked workdir the second bind hid them, and a bind at a spelling the jail had not established had no mount point: bwrap died with "Can't mkdir parents ... Read-only file system" and the launch failed outright. They now come after both binds and cover both spellings. Measured: before, the alias spelling could not launch; after, both refuse the write with EROFS. macOS measured containment against the caller's spelling alone, so a symlinked workdir rejected every runtime path and no write denial was emitted at all, while the allowance covered both spellings. It now compares against both and denies under both, and includes the framework build's top-level Python dyld image, which was the one file a later host subprocess maps. The optional search roots were resolved before being emitted, so a /usr/local/bin symlinked at the home directory became a recursive subpath over a home subtree. Homebrew on Intel chowns /usr/local to the user, so that is arrangeable. Each root and its target must now stay inside an approved prefix; ownership would have dropped the Homebrew trees this exists to keep working.
…ackages The containment test was lexical, and a venv invoked through a symlinked path keeps that alias in sys.prefix: measured on CPython 3.12, where <alias>/venv/bin/python reports sys.prefix = <alias>/venv rather than the resolved form. The caller hands in the canonical workdir, so an alias-prefixed path is not beneath it, and pairing the two lexical tests per spelling rejected every path either way round. Nothing was re-bound, and under bubblewrap 0.11 in a container a tool call overwrote the interpreter's sitecustomize through both spellings. Both backends now decide on the resolved path; after the change both spellings refuse with EROFS. The earlier regression tests missed this because they set sys.prefix to the canonical path, which is not what CPython reports here; the new ones use the alias. An editable PEP 420 namespace package has no __init__.py by design, so requiring one excluded it and an import that works in Studio's environment failed only inside a tool call. The distribution's own top_level.txt, and its normalised project name as the fallback, now name the top-level entries as well. Still only what the distribution declares, so the checkout does not come with it.
|
Recommend holding merge for the missing Require sandbox selector and Windows limitation disclosures. Native A/B checks confirm Windows isolation and passing Linux paths. Both macOS revisions fail the same Seatbelt probe in unchanged code from #10526, so macOS compatibility remains unresolved. Twelve Playwright scenes across Chromium, Firefox and WebKit confirm the UI gaps. Add the controls and disclosures, then resolve the shared macOS failure before merging. |
…nder root Follow-ups from reviewing 400af0f and bdcf91c. Keeping non-ASCII raw is right, and I confirmed it against a real kernel on macos-15: with json's default spelling the accented workdir is NOT writable inside the sandbox (sandbox-exec rc=1, the canary never appears), and with the raw spelling it is (rc=0, written). The other half of that change is that the profile is an argv string, so a path carrying undecodable bytes, which surrogateescape presents as a lone surrogate, now raises at the spawn rather than producing a rule that matches nothing. In `auto` an exception there is caught and the call runs unisolated, which is the same silent loss the raw spelling exists to prevent, so _validated refuses it where the caller can still see it. Three tests assert that a path the invoking user cannot read or cannot write is refused. As uid 0 the mode bits do not apply, so the premise is void and they fail for a reason that has nothing to do with the code. That is easy to hit now, since a container is the obvious place to run these when the host cannot build a sandbox. Skipped there instead, with the reason.
Resolve overlapping sandbox lifecycle and stream-event changes while preserving Windows SRT isolation, execution metadata, and context-window handling.
|
Thanks for the update on saved Required selections; I still need the Windows startup number for the new SRT probe, since the validator at studio/backend/models/inference.py now rejects previously valid tool_execution_mode values on every platform. Could you also split the shared controls and mode change from the vendored Windows runtime once #10526 lands and this retargets main? |
Summary
Add Windows SRT isolation for Python and Terminal calls, while retaining #10526's native bubblewrap and Seatbelt backends. Default to Auto on every platform and offer Require
sandbox through shared controls.
BREAKING CHANGE
tool_execution_modeaccepts onlyautoandrequired; omitted values default toauto. Full access remains behind the existing permission confirmation.Preserve saved Required selections. Clear obsolete Limited/nested grants and retain Required until the user selects a supported mode.
Changes
@anthropic-ai/[email protected]helper. Keep SRT installation, imports and startup probes Windows-only.Related
Depends on #10526 and targets
studio-minimal-sandbox. Selectively ports Windows support from #10441.After #10526 merges, reconcile against its merged revision and retarget to
main.