skip to content

Why can Claude Code's Bash sandbox let commands run without a prompt, and how do you turn it on on each platform?

level: juniorimportance: should knowfreq 22%

answer

  1. boundary replaces the prompt
  2. off until you opt in
  3. Seatbelt versus bubblewrap
  4. socat relays traffic to the proxy
  5. what happens when it cannot start

basics

~20 s

The operating system confines each command's files and network, so the boundary can stand in for a prompt. It is off by default: run /sandbox or set sandbox.enabled. macOS uses built-in Seatbelt; Linux and WSL2 need bubblewrap and socat.

solid answer

~40 s

A prompt asks you to judge a command *before* it runs; the sandbox limits what the command can touch *while* it runs, and the operating system enforces that limit on the command and every child process. Because the damage is bounded, Claude Code can auto-approve sandboxed commands. The sandbox is off by default: run `/sandbox` in a session, or set `sandbox.enabled` to `true` in a settings file. On macOS it uses the built-in Seatbelt framework, so there is nothing to install. On Linux and WSL2 it needs `bubblewrap` for filesystem isolation and `socat` to relay traffic to the sandbox proxy. WSL1 is not supported, and on native Windows commands run unsandboxed. If the sandbox cannot start, Claude Code runs commands unsandboxed unless `sandbox.failIfUnavailable` is `true`.

go deeper

for a junior

Explain why a limit the operating system enforces can replace a per-command prompt, and name Seatbelt for macOS and bubblewrap plus socat for Linux and WSL2.

for a middle

Know that the sandbox is off by default, where /sandbox saves its choice, and that a sandbox that cannot start falls back to running commands unsandboxed.

for a senior

Show that you verify the boundary with commands Claude runs, not ones you type, and use failIfUnavailable wherever the sandbox is a control rather than a convenience.

for a principal

Frame the sandbox as one layer: it bounds shell commands, while file tools, hooks and MCP servers need other controls or an outer container.

## The problem the sandbox solves Claude Code runs shell commands **as you**: same user, same files, same network. The usual control is a **permission prompt**: Claude proposes `npm test`, you read it and approve. That works for a handful of commands, but during a long build-and-fix loop the prompts pile up and people start approving without reading. A prompt protects you only while you are paying attention. The **Bash sandbox** is a different kind of control. It is a boundary the **operating system** enforces around each shell command Claude runs (Bash, PowerShell and Monitor commands) and every process those commands start. You decide which paths the command may write and which network hosts it may reach, and the kernel refuses everything else, whatever the command turns out to do. Because the possible damage has a hard limit, Claude Code can safely **auto-approve** sandboxed commands instead of asking about each one. In short, the boundary takes the place of the prompt. ## Turning it on The sandbox is **off by default**. There are three common ways to enable it: 1. Run `/sandbox` in a session. The panel has a **Mode** tab (auto-allow or regular permissions), an **Overrides** tab (whether failed commands may fall back to running unsandboxed) and a **Config** tab showing the resolved settings. Choosing a mode saves to `.claude/settings.local.json`, so it applies to the current project only. 2. Set `sandbox.enabled` to `true` in `~/.claude/settings.json` to sandbox every project. 3. For one session only, pass it inline: `claude --settings '{"sandbox": {"enabled": true}}'`. Organizations can also require it through managed settings, which take precedence over what a developer sets. ## What each platform uses | Platform | Enforcement | What you install | | --- | --- | --- | | macOS | Seatbelt, the built-in sandbox framework | Nothing | | Linux | bubblewrap, plus socat for network relay | `bubblewrap` and `socat` from the package manager | | WSL2 | Same as Linux | Same as Linux | | WSL1 | Not supported (`Sandboxing requires WSL2`) | Upgrade to WSL2 | | Native Windows | No sandbox; commands run unsandboxed | Run Claude Code inside WSL2 or a container | On Linux, the `/sandbox` panel shows a **Dependencies** tab when something is missing: `bubblewrap` and `socat` are required, ripgrep is bundled with the native binary, and a seccomp filter that blocks Unix domain sockets is optional. When a required package is missing, Dependencies is the only tab shown. The dependency check runs at startup, so restart Claude Code after installing. On Ubuntu 24.04 and later, AppArmor may stop bubblewrap from creating user namespaces; the docs give a small AppArmor profile for `bwrap` to fix that. Under the hood, Claude Code builds the sandbox on the open source `@anthropic-ai/sandbox-runtime` package. ## What happens when it cannot start This default surprises people. If `sandbox.enabled` is `true` but the sandbox cannot start (a missing dependency, or an unsupported platform), Claude Code **runs commands unsandboxed** and keeps working. To make it exit at startup instead, set `sandbox.failIfUnavailable` to `true`. A team that treats the sandbox as a security control needs that setting; a developer trying it out usually does not. ## Checking that it really works Ask **Claude** to run these commands. Typing them yourself at the `!` shell-mode prompt is not a test, because those commands usually run outside the sandbox. - `touch ~/sandbox-probe` should fail with `Operation not permitted` on macOS or `Read-only file system` on Linux and WSL2, because your home directory is outside the default write area. - `curl --noproxy '*' https://example.com` should fail with `Could not resolve host`, because a sandboxed command has no route that bypasses the sandbox proxy. If Claude offers to retry a failed probe outside the sandbox, decline. Accepting would prove nothing. ## What it is not - It is **not a permission mode**. Modes decide whether a tool call runs and whether you are asked first. The sandbox decides what a Bash command can reach once it runs. The two layers combine. - It covers **shell commands only**. Claude's file tools, MCP servers and hooks run outside it, which is why heavier isolation such as containers and VMs exists. - It **reduces risk without removing it**. A broad network allowlist or a broad write grant can undo much of what it protects.

  • You enable the sandbox on a Linux box that lacks bubblewrap. What happens, and how do you make that a hard failure?
    `/sandbox` shows only its Dependencies tab, naming the missing package. Commands Claude runs still execute, but unsandboxed, because the default is to fall back rather than stop. Set `sandbox.failIfUnavailable` to `true` and Claude Code exits at startup instead. Install `bubblewrap` and `socat`, then restart, since the dependency check runs only at startup.
  • You picked auto-allow in the /sandbox panel. Where did that choice go, and how do you apply it to every project?
    The panel writes to `.claude/settings.local.json`, so it applies only to the current project, and Claude Code adds that file to your global gitignore. To sandbox every project, set `sandbox.enabled` to `true` in `~/.claude/settings.json`. For a single session without writing any file, start Claude Code with `--settings` and inline JSON.

  • The sandbox is on by default as soon as Claude Code is installed.
  • On Linux the sandbox uses Seatbelt, the same as macOS.
  • WSL1 sandboxes commands the same way WSL2 does.
  • By default, a missing bubblewrap stops Claude Code from running any command.
  • The sandbox is one of the permission modes in the Shift+Tab cycle.
  • Typing a probe command at the ! prompt proves the sandbox works.