Docs
Refer a friend. Get a weekly-quota reset.Friend signs up and uses it → +1 reset (valid 30 days) · up to 10% cash back on their spend.
+1 resetGenerate link

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 /sandbox settings 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.enabledMeaning
false (default)Commands run on the host under ordinary permissions
trueModel-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:

json
{ "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 whatever CRABCODE_CONFIG_DIR / CRABCODE_HOME point at), the legacy .crabcode*.json file, 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/ and plugins/. Those are content, not credentials, and reading them is an everyday action inside the sandbox.
  • To deny more: sandbox.filesystem.denyRead, plus Read(...) rules under permissions.deny.
  • sandbox.filesystem.allowRead only 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-dir records)
  • sandbox.filesystem.allowWrite
  • Paths from Edit(...) rules under permissions.allow
  • In a git worktree session, the main repository's .git (needed for index.lock and 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 / config in the working directory (stops a planted bare-repo layout from being used to escape)
  • sandbox.filesystem.denyWrite, plus Edit(...) rules under permissions.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.

TierUnlisted hostKnock-on effects
ask (default)You are asked, three choicesFiltering proxy starts, egress is locked
allowAllowed silentlyAnd 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
denyAlways refusedThe 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.allowedDomains in 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:

  1. Switch to an HTTPS remote (for example move a git remote from git@… to https://…);
  2. Exclude the command: /sandbox exclude "ssh *", or Settings → Sandbox → commands that never enter the sandbox in the GUI;
  3. 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.allowUnixSockets allows specific paths (macOS only), sandbox.network.allowAllUnixSockets opens them all.

When something is blocked (three routes, in order)

  1. 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.
  2. 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 for unlisted (user layer only) these write this project's .crabcode/settings.local.json by default; add --user to write ~/.crabcode/settings.json instead. /sandbox status prints the effective posture (tier, the layer it came from, ignored layers, sandbox.network.allowLocalBinding, upstream proxy), and the Config tab of /sandbox lists every rule with its layer and removes the selected one on x.
    • GUI: add or remove directories / domains / excluded commands under Settings → Sandbox, and switch the tier for unlisted hosts there too.
  3. Re-run outside the box. While sandbox.allowUnsandboxedCommands is true (the default), the model may retry with dangerouslyDisableSandbox. 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 to false for the strict posture: the parameter is then ignored entirely and every command must either run sandboxed or be listed in sandbox.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

PlatformMechanismFilesystem rulesNetwork domain rules
macOSSeatbelt (the interface behind sandbox-exec)Fully enforced, verified rule by rule at runtime after the profile is appliedEnforced while the filtering proxy is running (egress lock allows only the proxy port)
Linux / WSL2Landlock + seccompGrants are enforced; denials inside a granted subtree depend on whether this machine allows unprivileged mount namespacesEnforced (Landlock single-port network rule plus an egress canary that proves it)
WindowsRestricted token + Job objectPath rules are not appliedDomain filtering is not applied
  • Fidelity has exactly two levels, full and partial. On partial, the rules that were promised but cannot be enforced on this machine are listed by name (/sandbox status and the GUI status card both show them). The direction is always conservative: if it cannot be computed, it reports partial.
  • Only full grants the sandbox's approval waiver (sandbox.autoAllowBashIfSandboxed, default true). 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.failIfUnavailable set to true) 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 /sandbox panel 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.unlistedHosts to allow or deny in the policy layer.
  • In dontAsk mode nothing is prompted at all, so a network prompt becomes a refusal (annotation ask-unavailable:dontAsk).
  • Approving a command and allowing a host are two different things: Bash(...) rules under permissions.allow carry no network grant.

Managed policy (fleet deployments)

Managed policySettings is the highest-priority layer:

  • Setting sandbox.enabled to true there makes it unchangeable by the user, and forces sandbox.allowUnsandboxedCommands off at the same time (locking the sandbox without locking the escape hatch is not locking anything).
  • sandbox.filesystem.allowManagedReadPathsOnly flips the read policy from open to allow-list: only sandbox.filesystem.allowRead from policySettings is readable, everything else is refused.
  • sandbox.network.allowManagedDomainsOnly honours allowed domains only from policySettings; user, project, local and flag layers are ignored for allows, while denies from every layer still apply. Unlisted hosts are refused without a prompt (annotation not-in-managed-allowlist), and the prompt never offers "allow permanently".
  • sandbox.network.unlistedHosts set in this layer pins the tier fleet-wide; neither the user layer nor the project layer can override it.
  • sandbox.failIfUnavailable turns "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; allows com.apple.trustd.agent so Go-based CLIs (gh, gcloud, terraform) can verify TLS behind a filtering proxy with a custom CA. Reduces security; default false.
  • 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.