Vibe Coding for Production
Secure execution

Sandbox mode

Claude Code bash sandboxing on macOS, Linux, and WSL2; common settings and how sandboxing interacts with permissions.

Sandboxing isolates Bash (and child processes) using OS primitives: Seatbelt on macOS, bubblewrap on Linux and WSL2. It does not replace Read / Edit tools, which still follow permissions directly.

Concepts and workflows: Sandboxing. Configuration reference: Settings: Sandbox settings (table below is aligned with that page).

/sandbox in the CLI

Run /sandbox to open the interactive menu (modes, dependency hints on Linux). If the sandbox cannot start and failIfUnavailable is false, Claude Code warns and may run commands without the sandbox.

Prerequisites

Works out of the box.

Install bubblewrap and socat (see the sandboxing doc for distro commands).

Use WSL2 with bubblewrap and socat installed. WSL1 is not supported.

Sandbox modes (behavior)

From Sandboxing:

  • Auto-allow: sandboxed commands are auto-approved when they fit the sandbox. Commands that cannot be sandboxed (for example non-allowed network hosts) fall back to the normal permission flow. rm / rmdir targeting /, home, or other critical paths can still prompt.
  • Regular permissions: every Bash command goes through the normal permission flow even inside the sandbox.

Auto-allow is independent of acceptEdits: sandboxed Bash may run without prompting while file-edit tools still follow the active permission mode.

Common sandbox settings

These commonly used keys live under sandbox in settings.json (user, project, local, or managed). The live settings reference is authoritative and also covers advanced runtime paths, Apple Events, strict network allowlists/TLS termination, filesystem disabling, violation handling, and the full credentials group. Arrays merge across scopes unless a flag says otherwise.

KeyPurpose
enabledTurn bash sandboxing on (macOS, Linux, WSL2). Default false.
failIfUnavailableIf true, exit at startup when the sandbox cannot start. If false (default), warn and run unsandboxed. For managed deployments that require a hard gate.
autoAllowBashIfSandboxedAuto-approve bash when sandboxed. Default true.
excludedCommandsPatterns that always run outside the sandbox (example: ["docker *"]). Use when a tool is incompatible with the sandbox.
allowUnsandboxedCommandsIf true (default), Claude may retry with dangerouslyDisableSandbox after a failure (goes through permissions). If false, that escape hatch is disabled; everything must be sandboxed or listed in excludedCommands.
filesystem.allowWriteExtra write paths for subprocesses (merged with Edit(...) allows).
filesystem.denyWriteBlock writes for subprocesses (merged with Edit(...) denies).
filesystem.denyReadBlock reads for subprocesses (merged with Read(...) denies).
filesystem.allowReadRe-allow reads inside a denied region; wins over denyRead.
filesystem.allowManagedReadPathsOnlyManaged only: only managed allowRead entries apply; denyRead still merges from all sources. Default false.
network.allowUnixSocketsmacOS: explicit Unix socket paths allowed in the sandbox. Ignored on Linux/WSL2.
network.allowAllUnixSocketsLinux/WSL2: allow all Unix sockets (broad; often needed because seccomp cannot filter by path). Default false.
network.allowLocalBindingmacOS: allow binding localhost ports. Default false.
network.allowMachLookupmacOS: extra XPC/Mach service names (trailing * allowed). For Simulator, Playwright, etc.
network.allowedDomainsOutbound allow list (wildcards such as *.example.com).
network.deniedDomainsOutbound deny list; wins when both match.
network.allowManagedDomainsOnlyManaged only: only managed allowedDomains and managed WebFetch allows count; others ignored; non-allowed domains blocked without prompting. Default false.
network.httpProxyPortBring-your-own HTTP proxy port (optional).
network.socksProxyPortBring-your-own SOCKS proxy port (optional).
enableWeakerNestedSandboxLinux/WSL2: weaker sandbox for unprivileged Docker; reduces isolation. Default false.
enableWeakerNetworkIsolationmacOS: allow trustd for TLS when using httpProxyPort with MITM/custom CA; weakens network isolation. Default false.

Path prefixes (filesystem.*)

PrefixMeaning
/Absolute from filesystem root
~/Under your home directory
./ or no prefixProject root for project settings, or ~/.claude for user settings

Sandbox path rules differ from Read / Edit permission rule path syntax; see the settings doc.

Example configuration

{
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": false,
    "autoAllowBashIfSandboxed": true,
    "excludedCommands": ["docker *"],
    "allowUnsandboxedCommands": true,
    "filesystem": {
      "allowWrite": ["/tmp/build", "~/.kube"],
      "denyRead": ["~/.aws/credentials"]
    },
    "network": {
      "allowedDomains": ["github.com", "*.npmjs.org", "registry.yarnpkg.com"],
      "deniedDomains": ["uploads.github.com"],
      "allowUnixSockets": ["/var/run/docker.sock"],
      "allowLocalBinding": true
    }
  }
}

Unix sockets and Docker

Allowing /var/run/docker.sock effectively grants host-level access via the Docker API. Only allow sockets you truly need, per the Sandboxing security notes.

How sandboxing fits secure execution

  • Permissions gate which tools run. Sandbox constrains what Bash can touch on disk and network after a command is approved.
  • Combine with permissions.deny on .env and other secrets so Read tools cannot leak them even when Bash is boxed.
  • Auto mode still routes risky actions through its classifier; sandbox network requests are not implicitly trusted.

Example prompt

When a sandboxed command fails, paste the error and terminal context:

This npm script failed inside the sandbox. From the error, recommend the smallest settings.json change: excludedCommands, allowUnsandboxedCommands, or network.allowedDomains. Explain the security tradeoff in two sentences.

@terminal:npm

See also

On this page