Repository navigation
feat(core): sandbox agent shell commands with MXC - #64093
Draft
benjaminfrombe wants to merge 2 commits into
Draft
benjaminfrombe wants to merge 2 commits into
benjaminfrombe wants to merge 2 commits into
Conversation
Opt-in OS-level sandbox for the shell tool, enforced by Microsoft MXC (Seatbelt on macOS, bubblewrap on Linux, ProcessContainer on Windows). - sandbox config block, default off; an invalid block resolves to the strictest policy instead of being dropped - settings are honored from user-level config only: a repository cannot enable, loosen or tighten the sandbox or add writable roots - read-only and workspace-write modes, network deny by default - protected config paths (opencode.json, .opencode, .claude, .agents) cannot be written or planted by a sandboxed command, closing the restart escape; denied outright on Windows where read-only carve-outs are not enforced - fail-closed everywhere: unsupported platform, missing backend, remote workspace, or a network-deny policy Windows cannot enforce yet means the command does not run, never a silent unconfined fallback - separate shell_unsandboxed permission, asserted before the shell approval, so approving a sandboxed command never approves escaping it - live enforcement tests gated on backend availability: macOS Seatbelt and Windows ProcessContainer verified end to end Addresses the sandboxed-execution part of anomalyco#48411. Supersedes anomalyco#63599.
bwrap cannot bind a read-only source that does not exist, which fails the whole launch, and the backend's deniedPaths fallback creates the missing path as a stray directory on the host (microsoft/mxc#1780). Linux now carves out protected paths that exist and leaves the rest alone in v1, documented as a known gap; macOS and Windows behavior is unchanged. Verified on Debian 13 with bwrap 0.12: read-only carve-outs for existing paths are enforced (write denied, read allowed), network egress denied, read-only mode enforced, timeout kill works.
1 task done
This branch has not been deployed
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.
Issue for this PR
Addresses the sandboxed-execution part of #48411. Supersedes #63599 (see below).
Type of change
What does this PR do?
Opt-in OS-level sandbox for the shell tool, enforced by Microsoft MXC (
@microsoft/mxc-sdk): Seatbelt on macOS, bubblewrap on Linux, ProcessContainer on Windows. Off by default;sandbox.enabled: truein user config turns it on.Design decisions, and how this differs from #63599:
opencode.json,opencode.jsonc,.opencode,.claudeand.agentscannot be written or planted by a sandboxed command. On macOS that includes paths that do not exist yet (verified: a fresh-workspace planting attempt is denied). On Linux, paths that exist are enforced as read-only carve-outs, but bwrap cannot bind a missing read-only source and the backend's deny fallback creates the missing path as a stray host directory (reported upstream: Linux bubblewrap: deniedPaths for a nonexistent path creates a stray directory on the host that persists after exit microsoft/mxc#1780), so not-yet-existing paths are left unprotected there in v1, as a documented gap. On Windows, where the backend does not enforce read-only carve-outs under a writable root at all, protected paths are denied outright instead. This addresses the blocking review finding on feat(core): add opt-in OS-level shell sandbox #63599.sandboxblock normalizes to the strictest policy instead of being dropped (kept from feat(core): add opt-in OS-level shell sandbox #63599).sandboxinput;sandbox: falseassertsshell_unsandboxed(shipped asask, after the*allow) before the ordinaryshellapproval, so approving a sandboxed command never approves running it unsandboxed. Deny/allow rules onshell_unsandboxedact as the escalation policy, the equivalent of Codex's escalation modes.Shell.Service, so user!commands and plugin shells are not confined (a review point on feat(core): add opt-in OS-level shell sandbox #63599). Policy is pinned per Location in an Effect service, not a module-level Map.readable_rootsis dropped: the backend allows reads outside writable roots by default, so it would be dead config.Known limitations, stated up front:
network: "deny"fails closed there with an explanation until MXC can enforce it. Filesystem-only sandboxing on Windows is available by settingnetwork: "allow"explicitly.koffiis added totrustedDependencies(its postinstall fetches prebuilds; bun blocks it by default).No feature flag: the
sandboxconfig block defaults to off, which is the gate; the PR is a draft pending the design review CONTRIBUTING.md asks for, and #63599 may be closed in favor of it if the approach is approved.How did you verify your code works?
cd packages/core && bun run typecheck:tscclean (bun checkneeds bun 1.4.4; my local bun is 1.4.2, so I used the tsc variant CI treats as source of truth).bun run script/test.ts test/sandbox.test.ts: 21 pass, 2 skip (Windows-only cases), 0 fail. The live tests, gated on MXC backend availability, run the real macOS Seatbelt backend: write inside allowed, write outside denied, config and plugin planting denied (existing and not-yet-existing paths), network egress denied, read-only mode enforced, timeout kills the command.test/tool-shell.test.ts: 101 pass, 0 fail, including 4 new tests (routes through the sandbox, timeout notice,shell_unsandboxedasserted beforeshell, no escape prompt when the sandbox is off).test/agent.test.ts,test/config/normalization.test.ts,test/subagent-idle-e2e.test.ts: 68 pass, 0 fail.packages/schema: 93 pass, 0 fail.opencode.jsonand.opencode/pluginsplanting denied,deniedPathsenforced, and the network-deny gap that motivates the fail-closed Windows behavior.opencode.jsonread-only (write denied, read allowed), read-only mode enforced, network egress denied (curlexit 6), timeout kill withtimedOut: true. Also surfaced the two upstream behaviors (missing readonly source fails the launch; missing denied path creates a stray host directory) that shape the documented Linux gap, Linux bubblewrap: deniedPaths for a nonexistent path creates a stray directory on the host that persists after exit microsoft/mxc#1780.tool-outputemoji split), which also fails on pristinedev(verified withgit stash), so zero new failures from this branch.Screenshots / recordings
Not a UI change.
Checklist