Repository navigation
feat(sandbox): core module for the bubblewrap sandbox of third-party servers - #743
Merged
Merged
Conversation
…servers `tole_core::sandbox` (Linux bubblewrap, #601, docs/sandbox-design.md and the owner decisions of 2026-11-14): profiles (`server`, `strict`; network none or host), the pure `bwrap_args` builder, `check_grant`, backend detection (`bwrap --version` plus a smoke run), and `plan`, which decides one launch: sandboxed, direct, or refused. Every launch unshares all namespaces including the user one, disables nested user namespaces and drops all capabilities; the only `--setenv` values are HOME and TMPDIR; the caller spawns bwrap with the scrubbed environment. Grants are resolved and refused when they are or hold `/`, `/proc`, `/sys`, `/dev`, $HOME or the tole data dir, or sit inside the data dir. The owner policy is set once per process; the workspace is an argument of each launch. Not wired yet: nothing calls it, so behaviour is unchanged. The wiring follows in its own PR. Refs #601
| let ws = env.workspace.as_deref(); | ||
| if p.profile.workspace != Workspace::None { | ||
| let ws = ws.ok_or("no workspace to bind")?; | ||
| check_grant(ws, home, data_dir)?; |
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
`check_grant` validated the resolved path but the plan then handed the original spelling to bwrap, which resolves a source symlink at exec time: a link swapped after the check could mount `/` or `$HOME`, writable for a workspace or `write` grant. `check_grant` now returns the resolved path and the argument builder only ever receives that one (workspace, read, write and the server's install dir; the program is addressed through the resolved dir). The plan is rebuilt for every launch, right before the spawn, so a swapped link is re-resolved or refused. The remaining same-user race is documented in the design note. Refs #601
This was referenced Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
PR 1a of the first slice of the sandbox (#601,
docs/sandbox-design.md, owner decisions of 2026-11-14): the core moduletole_core::sandbox. Nothing calls it yet, so behaviour is unchanged. The wiring (stdio MCP launch,[sandbox]config,tole doctor, integration tests) is PR 1b, stacked on this one (#734).Why
Scrubbing a child's environment is not a durable boundary (#594 audit). The design picked bubblewrap with an argument list built by tole. Splitting keeps each review small enough to read in full: this PR is the pure, unit-tested part.
Changes
tole_core::sandbox(new): profile types (server: workspace read-only;strict: no workspace; networknoneorhost), the purebwrap_argsbuilder,check_grant, backend detection (bwrap --version>= 0.8 plus abwrap --ro-bind / / truesmoke run, cached; Linux only, other platforms report no sandbox), andplan, which decides one launch (sandboxed, direct, or refused) from the owner policy:requiredrefuses without a working bwrap;optionalwarns when attended and refuses when unattended (owner decision 2).--unshare-all --unshare-user --disable-userns --cap-drop ALL --new-session --die-with-parent, a private/proc, a read-only system view,.git/hooks,.git/configand.toleread-only under a writable workspace, and--setenvonly forHOMEandTMPDIR(never a secret). The caller spawns bwrap with the scrubbed environment (PR 1b).check_grantresolves the path (symlinks,.., trailing slash, relative) and refuses one that cannot be resolved,/,/proc,/sys,/dev,$HOMEand every ancestor of it, the tole data dir, its inside and its ancestors; with$HOMEunknown, an ancestor of/homeor/root. It returns the resolved path, and ONLY that path reaches the builder (workspace,read,write, the server's install dir, the program through it), as both bind source and destination. The plan is rebuilt for every launch, right before the spawn, so a link swapped later is re-resolved or refused. The remaining same-user race between the last resolution and bubblewrap's mount is documented in the design note.set_policyrefuses a different second value); the workspace is an argument of each launch, never shared state. The unattended flag is process-wide and monotone.paths::canon_lenientbecomespub(crate). Docs: design status, the grant-resolution note and the epics line.Testing
cargo fmt,cargo clippy --workspace --all-targets --all-features -D warnings,cargo test -p tole-core(also--no-default-features).bwrap_argsmakes a test fail (all killed).$HOMEwith the data dir elsewhere, ancestor of a data dir outside$HOME, inside the data dir, symlink to$HOME,.., trailing slash, unresolvable path,/,/proc,/sys,/dev, no$HOME); mutation checks kill every rule except the explicit/test, which$HOME's ancestor rule also covers.read,writeand install dir are bound as their resolved targets and the argv never holds the link; a property-style test over links,..and trailing slashes checks every path in the argv under the tree equals the validated one; a link swapped between launches is followed to its new target or refused when it now points at$HOME. Mutants that pass the original workspace, the original read/write paths or the original install dir are each killed.requiredwithout bwrap refuses;optionalwarns when attended and refuses when unattended; a skipped server is never wrapped; a workspace holding the data dir refuses; sessions planning concurrently each get their own workspace bind and a later launch never changes an earlier argv.cfg(unix); the Linux-only probe iscfg(target_os = "linux"). Not run here: Windows and macOS builds (no cross C toolchain forring); CI covers them.Refs #601