Sandboxing
Put model-issued bash commands inside OS-level isolation: writes are confined to the workspace, domains are allowed on request, and reads stay open except for wrok Code's own credential directories, which are denied unconditionally.
When you see this doc
- "Learn more" on the
/sandboxsettings screen - "Learn more" on the GUI's Settings → Sandbox page
- The annotation attached to a command the sandbox blocked
Two states, not three
The sandbox is either on or off, decided by sandbox.enabled. Default: off.
sandbox.enabled | Meaning |
|---|---|
false (default) | Commands run on the host under ordinary permissions |
true | Model-issued bash commands are prefixed with crabcode sandbox-exec and isolated per the matrix below |
There is no off / auto / on triple, and no sandbox mode key of any name — that scheme came from an earlier documentation draft and never existed in the product.
To switch: run /sandbox in the TUI, use Settings → Sandbox in the GUI, or edit settings.json directly:
{ "sandbox": { "enabled": true } }{ "sandbox": { "enabled": true } }The layer you write to decides the scope: ~/.crabcode/settings.json (every project on this machine), .crabcode/settings.json (committed, shared with the team), .crabcode/settings.local.json (this project, git-ignored). Later layers win.
The default read / write / network matrix
Turning the sandbox on gives you all of this with no further configuration. Everything else below is additive on top of it.
Reads: open by default, credentials denied unconditionally
- The default read policy is open:
/usr/lib, system headers and other project directories are all readable. Most users never configure read rules, and the sandbox should not lock them out of the standard library because of that. - Unconditionally denied: wrok Code's config root (
~/.crabcode, plus whateverCRABCODE_CONFIG_DIR/CRABCODE_HOMEpoint at), the legacy.crabcode*.jsonfile, and the gateway state directory. Locking the sandbox without locking credentials is not locking anything. - Two carve-outs are punched back into those roots:
skills/andplugins/. Those are content, not credentials, and reading them is an everyday action inside the sandbox. - To deny more:
sandbox.filesystem.denyRead, plusRead(...)rules underpermissions.deny. sandbox.filesystem.allowReadonly means anything under the managed allow-list read policy (see Managed policy below). With the default open read policy, setting it has no effect.
Writes: the workspace and nothing else
Writable locations (union):
- The current working directory
- wrok Code's temp directory (a command writes a probe file there so the host can propagate
cd) permissions.additionalDirectories(what--add-dir//add-dirrecords)sandbox.filesystem.allowWrite- Paths from
Edit(...)rules underpermissions.allow - In a git worktree session, the main repository's
.git(needed forindex.lockand friends)
Carved back out of the allowed set (writes denied):
- Every settings file and the managed-policy drop-in directory — otherwise a sandboxed command could rewrite its own isolation rules
.crabcode/skills(skills carry the same privilege level as commands)HEAD/objects/refs/hooks/configin the working directory (stops a planted bare-repo layout from being used to escape)sandbox.filesystem.denyWrite, plusEdit(...)rules underpermissions.deny
Network: hosts outside the allowlist are referred to you first
Outbound traffic goes through a loopback filtering proxy that runs only on this machine. It looks at the hostname (and the destination port when a rule names one) and nothing else — no decryption, no payload inspection. While the proxy is running, the sandboxed process's TCP egress is locked to that port: a program that bypasses the proxy and calls socket() directly is refused by the kernel. Platforms that cannot lock egress are listed under Platform mechanisms.
Both sources of allowed domains count: sandbox.network.allowedDomains and WebFetch(domain:...) rules under permissions.allow. Denied domains come only from WebFetch(domain:...) rules under permissions.deny.
Entries in both lists may end in a :port suffix: api.example.com:443 matches port 443 only, and an entry without a port matches every port (*.example.com:8443 and .example.com:80 work the same way). A port is a number from 1 to 65535 without leading zeros; an IPv6 address with a port must be bracketed, [2001:db8::1]:443, while an unbracketed IPv6 address is taken whole and never split. /sandbox allow-domain / deny-domain and the GUI reject a malformed port when you write it (a deny entry written wrong would silently never match, so it is not let through). Session grants and prompts stay per thread × host, regardless of port. The WebFetch(domain:...) tool itself matches hostnames only, so a rule with a port has no effect on it and applies only to the sandbox proxy.
To tell the model why a deny rule exists, add one sentence under sandbox.network.deniedDomainReasons, keyed by the exact text of the deny entry (for example {"github.com:22": "SSH pushes are blocked; use an https remote"}). When that rule blocks a connection the sentence appears in the way-out part of the violation annotation. A key must equal the rule entry character for character; a key with no matching rule never fires.
What happens to a host that is not on the allowlist is decided by sandbox.network.unlistedHosts — the single source of truth for that tier. It is never inferred from whether the domain lists happen to be empty.
| Tier | Unlisted host | Knock-on effects |
|---|---|---|
ask (default) | You are asked, three choices | Filtering proxy starts, egress is locked |
allow | Allowed silently | And when there are no denied domains and no managed allow-list mode, the proxy does not even start and egress is not locked — byte-for-byte the old "no rules configured, no isolation" behaviour |
deny | Always refused | The allowlist is the whole set; proxy starts, egress is locked |
The tier is read from three layers only
sandbox.network.unlistedHosts is read only from the managed policy layer, the command-line flag layer, and the user layer (highest priority first). The same key written into .crabcode/settings.json (project layer) or .crabcode/settings.local.json (local layer) is ignored, and /sandbox status names every ignored layer and its value. The reason: a cloned repository must not be able to switch your domain filtering off through a settings file it ships with. Every other network key (sandbox.network.allowedDomains included) still merges across all layers as usual.
The three choices when you are asked
- Allow for this session — held in memory only; gone when the process restarts.
- Allow permanently — written to
sandbox.network.allowedDomainsin this project's.crabcode/settings.local.json. Rules are hot-swapped: a command already running does not lose its connection, and the proxy port stays the same for the whole session. - Deny — the default focus. The same host is not asked about again within the same command; the next command asks again.
Concurrent connections to the same host produce one prompt, and the answer is delivered to every waiter at once.
If nobody can answer, the connection is refused: headless without --permission-prompt-tool, permission mode dontAsk, or a turn that already ended or was interrupted. The annotation reads ask-unavailable:<why> — that is not a network failure and retrying will not help. Pre-configure sandbox.network.allowedDomains, or set the tier to allow / deny.
Upstream proxies: the sandbox goes through yours
Once a connection is allowed, it is forwarded through the upstream proxy you configured (whatever HTTPS_PROXY / HTTP_PROXY points at), and /proxy use-system takes effect mid-session. Only http: upstreams are supported; https: / socks5: and friends log one warning and then connect directly — never a pretend success.
git's per-URL proxy (http.<url>.proxy pointing at a local port) does not work behind the egress lock: the kernel only allows the filtering proxy's own port. Use an environment-level proxy inside the sandbox.
Local ports: the sandbox.network.allowLocalBinding boundary
Default true: starting a dev server or a local mock API is one of the most common legitimate actions inside the sandbox, and its exposure is loopback-only. The cost is that every port on this machine is reachable (including a local upstream proxy) — turn it off if you want the domain allowlist to be the whole story. With it off, connections to local ports are refused and the annotation reads local-binding-off (that key is what to change, not an allowlist entry).
On macOS the same key also decides whether the sandbox may listen on a local port: only with it on are loopback binds and inbound connections allowed. Binding 0.0.0.0 or an external address is still refused — exposing a service to the LAN should not be silently allowed by a sandbox.
Traffic that never reaches the filtering proxy
ssh, raw TCP and direct-IP connections never pass through an HTTP proxy; behind the egress lock the kernel refuses them outright and the annotation reads kernel-egress-denied with the host named. Three routes out:
- Switch to an HTTPS remote (for example move a git remote from
git@…tohttps://…); - Exclude the command:
/sandbox exclude "ssh *", or Settings → Sandbox → commands that never enter the sandbox in the GUI; - Let that one command be re-run outside the box (ordinary approval, asked every time).
Behind the macOS egress lock, Go-based CLIs (gh / gcloud / terraform) cannot verify TLS certificates and the annotation reads tls-trust-unavailable. The way out is sandbox.enableWeakerNetworkIsolation, or listing the command in sandbox.excludedCommands — do not disable certificate verification.
headless / CI
Nobody is there to answer, so either pre-configure the hosts in sandbox.network.allowedDomains or set the tier to allow. Under -p without --permission-prompt-tool, the process writes one line to stderr (once per process).
Platform and the rest
- Windows does not apply domain filtering, so nothing is ever asked (the three tiers stay editable and the UI marks them "not enforced on this platform").
- Unix sockets:
sandbox.network.allowUnixSocketsallows specific paths (macOS only),sandbox.network.allowAllUnixSocketsopens them all.
When something is blocked (three routes, in order)
- Change the approach inside the sandbox. The annotation names what was refused and on which axis: filesystem rules give the path and read / write / execute, network rules give
<host>:<port>and the reason (lines beginning with[network-denied]). If the refusal is wrok Code's own data directory, that route is closed by design — credentials are not allowlistable. - Have the user grant it.
- TUI, seven subcommands:
/sandbox status,allow-write <path>,deny-read <path>,allow-domain <host[:port]>,deny-domain <host[:port]>,unlisted <ask|allow|deny> [--user],exclude "<command pattern>" [--user]. Except forunlisted(user layer only) these write this project's.crabcode/settings.local.jsonby default; add--userto write~/.crabcode/settings.jsoninstead./sandbox statusprints the effective posture (tier, the layer it came from, ignored layers,sandbox.network.allowLocalBinding, upstream proxy), and the Config tab of/sandboxlists every rule with its layer and removes the selected one onx. - GUI: add or remove directories / domains / excluded commands under Settings → Sandbox, and switch the tier for unlisted hosts there too.
- TUI, seven subcommands:
- Re-run outside the box. While
sandbox.allowUnsandboxedCommandsistrue(the default), the model may retry withdangerouslyDisableSandbox. That command goes through ordinary approval (the sandbox auto-allow waiver does not apply), so the user sees "this command will run outside the sandbox" on the approval card and decides. Set it tofalsefor the strict posture: the parameter is then ignored entirely and every command must either run sandboxed or be listed insandbox.excludedCommands.
sandbox.excludedCommands is the list of command patterns that never enter the sandbox at all (for example a build tool that must talk to the host directly). It is not the escape hatch: one is declared up front, the other is a retry after a failure.
Platform mechanisms and fidelity
| Platform | Mechanism | Filesystem rules | Network domain rules |
|---|---|---|---|
| macOS | Seatbelt (the interface behind sandbox-exec) | Fully enforced, verified rule by rule at runtime after the profile is applied | Enforced while the filtering proxy is running (egress lock allows only the proxy port) |
| Linux / WSL2 | Landlock + seccomp | Grants are enforced; denials inside a granted subtree depend on whether this machine allows unprivileged mount namespaces | Enforced (Landlock single-port network rule plus an egress canary that proves it) |
| Windows | Restricted token + Job object | Path rules are not applied | Domain filtering is not applied |
- Fidelity has exactly two levels,
fullandpartial. Onpartial, the rules that were promised but cannot be enforced on this machine are listed by name (/sandbox statusand the GUI status card both show them). The direction is always conservative: if it cannot be computed, it reportspartial. - Only
fullgrants the sandbox's approval waiver (sandbox.autoAllowBashIfSandboxed, defaulttrue). So on Windows you still get the normal approval prompts even with the sandbox on. - PowerShell commands are not sandboxed on Windows: the sandboxed form of PowerShell needs a POSIX outer shell, which Windows does not have.
- If the backend cannot start, nothing ever runs unsandboxed in silence: the lenient posture degrades and discloses it (sticky for the session), while the strict posture (
sandbox.failIfUnavailableset totrue) refuses deterministically, and a runtime failure surfaces as exit code 125.
Interaction with permission modes
- When the effective permission mode is full access (
bypassPermissions), the sandbox does not apply to that session — the user has explicitly said they do not want anything held back. No filtering proxy, no egress lock, and no network prompts. The/sandboxpanel states this at the top. - Exception: when a managed policy locks the sandbox, full access does not outrank it. The sandbox still applies, network access is still referred to the user, and the escape hatch is locked along with it. An administrator who wants no prompts sets
sandbox.network.unlistedHoststoallowordenyin the policy layer. - In
dontAskmode nothing is prompted at all, so a network prompt becomes a refusal (annotationask-unavailable:dontAsk). - Approving a command and allowing a host are two different things:
Bash(...)rules underpermissions.allowcarry no network grant.
Managed policy (fleet deployments)
Managed policySettings is the highest-priority layer:
- Setting
sandbox.enabledtotruethere makes it unchangeable by the user, and forcessandbox.allowUnsandboxedCommandsoff at the same time (locking the sandbox without locking the escape hatch is not locking anything). sandbox.filesystem.allowManagedReadPathsOnlyflips the read policy from open to allow-list: onlysandbox.filesystem.allowReadfrompolicySettingsis readable, everything else is refused.sandbox.network.allowManagedDomainsOnlyhonours allowed domains only frompolicySettings; user, project, local and flag layers are ignored for allows, while denies from every layer still apply. Unlisted hosts are refused without a prompt (annotationnot-in-managed-allowlist), and the prompt never offers "allow permanently".sandbox.network.unlistedHostsset in this layer pins the tier fleet-wide; neither the user layer nor the project layer can override it.sandbox.failIfUnavailableturns "the sandbox could not start" into a startup failure instead of a warning.
Other available keys
sandbox.ignoreViolations— violation patterns you do not want annotated or counted.sandbox.enableWeakerNestedSandbox— permit the weaker nested-sandbox form.sandbox.enableWeakerNetworkIsolation— macOS only; allowscom.apple.trustd.agentso Go-based CLIs (gh, gcloud, terraform) can verify TLS behind a filtering proxy with a custom CA. Reduces security; defaultfalse.sandbox.network.httpProxyPort/sandbox.network.socksProxyPort— filtering proxy ports. The port actually used is assigned at runtime, and the SOCKS side is not implemented.sandbox.ripgrep— override the ripgrep command used inside the sandbox.