skip to content

How would you require Claude Code's Bash sandbox across a mixed macOS, Linux and Windows fleet without stranding developers on blocked tools?

level: principalimportance: should knowfreq 5%

answer

  1. managed booleans win, arrays merge
  2. fail closed or fall back
  3. admin-required ignores the repository
  4. locks for domains and read paths
  5. native Windows has no sandbox

basics

~20 s

Deliver sandbox.enabled, failIfUnavailable and allowUnsandboxedCommands: false through managed settings, add domain and read locks, ship approved tool exclusions centrally, and deliver it per operating system, because native Windows cannot sandbox and would refuse to start.

solid answer

~50 s

Start with managed settings that set `sandbox.enabled`, `failIfUnavailable: true` and `allowUnsandboxedCommands: false`. Managed Booleans override developers, and the strict-mode `false` makes the sandbox **admin-required**, so from v2.1.285 a repository's settings cannot loosen it. Array keys still merge from developers' own settings, so lock what matters: `network.allowManagedDomainsOnly` for hosts, `filesystem.allowManagedReadPathsOnly` for reads, and `false` for weakening keys such as `enableWeakerNestedSandbox` or `network.allowLocalBinding`. Add `credentials` deny entries for `~/.aws` and `~/.ssh`, since reads are open by default. Because repositories can no longer supply exclusions, ship the approved `excludedCommands` and `allowWrite` entries in managed settings. Native Windows has no sandbox, and with `failIfUnavailable` Claude Code exits there, so deliver the policy only to macOS and Linux, or move Windows users into WSL2 or a container. The trade-off is friction against escape routes: every lock moves a fix from the developer to the admin.

go deeper

for a junior

Know that an organization can require the sandbox centrally, and that managed values win over what a developer sets.

for a middle

Explain why Booleans override but arrays merge, and what failIfUnavailable and allowUnsandboxedCommands false each close.

for a senior

Ship sanctioned exclusions and write grants in managed settings, because an admin-required sandbox ignores the repository's own.

for a principal

Own the friction trade-off: which escape routes to close, how Windows users get a sandbox, and how a tool breakage becomes a central exception.

## The goal and the tension Requiring the sandbox is easy to state: every command Claude runs on every machine stays inside the boundary. The tension is that the sandbox breaks real tools. `docker` is incompatible with it, some Go-based CLIs fail TLS verification on macOS, and database drivers ignore the proxy. Each break has an escape route a developer or a repository can use. The policy has to close the escape routes you don't trust while keeping a sanctioned path for the tools you do. There is no single right configuration; there is a set of trade-offs you choose deliberately. ## The baseline managed policy Deliver the `sandbox` keys through managed settings, either a file pushed by device management or server-managed settings from the admin console. Delivery mechanics and file locations are covered elsewhere; what matters here is the keys. ```json { "sandbox": { "enabled": true, "failIfUnavailable": true, "allowUnsandboxedCommands": false, "excludedCommands": ["docker compose *"], "network": { "allowManagedDomainsOnly": true, "allowedDomains": ["registry.npmjs.org", "*.example.com"] }, "credentials": { "files": [{ "path": "~/.aws", "mode": "deny" }, { "path": "~/.ssh", "mode": "deny" }] } } } ``` - `enabled` turns it on. A managed Boolean overrides anything developers set. - `failIfUnavailable: true` makes Claude Code **exit at startup** rather than fall back to unsandboxed commands when a dependency is missing. - `allowUnsandboxedCommands: false` is strict sandbox mode. Claude Code ignores the `dangerouslyDisableSandbox` retry. ## How merging decides what a developer can still change | Kind of key | Managed behaviour | What a developer can still do | | --- | --- | --- | | Booleans (`enabled`, `failIfUnavailable`) | Managed value wins | Nothing | | Arrays (`allowedDomains`, `allowRead`, `allowWrite`, `excludedCommands`) | Merged across scopes | Append entries unless a lock covers the key | | Weakening Booleans (`enableWeakerNestedSandbox`, `enableWeakerNetworkIsolation`, `network.allowAllUnixSockets`, `network.allowLocalBinding`, `allowAppleEvents`) | Unset unless managed sets them | Turn them on from user settings or `--settings` | So the baseline is not airtight on its own. Add the locks that match your threat model: 1. `network.allowManagedDomainsOnly: true`: only managed `allowedDomains` and `WebFetch(domain:...)` allow rules count, and unlisted hosts are **blocked without a prompt**. 2. `filesystem.allowManagedReadPathsOnly: true`: only managed `allowRead` entries are honoured. 3. Set each weakening key to `false` in managed settings. ## The admin-required sandbox and repositories A managed `allowUnsandboxedCommands: false`, or a managed `allowManagedDomainsOnly: true`, makes the sandbox **admin-required**. From Claude Code v2.1.285, Claude Code then ignores the settings in a repository's `.claude/settings.json` and `.claude/settings.local.json` that would loosen it: `excludedCommands`, `network.allowedDomains`, proxy ports, write grants from `filesystem.allowWrite`, `Edit` allow rules and additional directories, and `true` values for the weakening keys. Neither setting turns the sandbox on by itself, so set `enabled` as well. Two consequences follow: - A cloned repository cannot quietly take `docker` out of the sandbox. - **Your sanctioned exclusions must ship in managed settings**, because repositories can no longer supply them. A developer's own `~/.claude/settings.json` can still add exclusions; no managed-only lock covers `excludedCommands`. A repository can still change `autoAllowBashIfSandboxed`, so set it centrally if approval behaviour matters to you. ## The mixed fleet The sandbox runs on macOS, Linux and WSL2 only. With `failIfUnavailable`, Claude Code **exits at startup on native Windows**. Your options: - Deliver the policy **per operating system**, as a managed file on macOS and Linux machines only. Server-managed settings apply to every user in the organization, Windows users included. - Move Windows users into **WSL2 or a container**, where the sandbox can run. ## What the policy still leaves open - Commands developers type at the `!` prompt run outside the sandbox in most sessions. That is the same access they already have in any terminal. - File tools, hooks and MCP servers are outside the Bash sandbox and need permission and MCP policy, or an outer container. - A broad allowed domain can become an exfiltration route, because the proxy decides by hostname and doesn't inspect TLS by default. Keep the managed allowlist narrow, or route traffic through a custom inspecting proxy. ## The trade-off to own Every lock moves a fix from the developer to the administrator. With `allowManagedDomainsOnly` on, a new registry means a ticket, not a prompt. Strict mode means a failing `git merge` on a protected path must be run by hand. Teams that over-lock push developers to run tools outside Claude Code; teams that under-lock leave a repository-controlled path out of the sandbox. A workable rollout starts strict on credentials and retries, measures which tools break, and adds narrow central exclusions instead of broad ones.

  • Managed settings enable the sandbox, but a developer still adds `api.example.org` to `allowedDomains` in their own settings and it works. Why?
    Array keys merge across the scopes a session loads, and a managed `sandbox.enabled` locks only that Boolean. To make the managed allowlist the only one, set `network.allowManagedDomainsOnly` to `true` in managed settings. Then only managed `allowedDomains` and `WebFetch(domain:...)` allow rules count, and unlisted hosts are blocked without a prompt.
  • After the rollout, `/sandbox` prints that sandbox settings are overridden by a higher-priority configuration. What should the developer check?
    A higher settings level sets `sandbox.enabled`, `autoAllowBashIfSandboxed` or `allowUnsandboxedCommands`, so the panel can't save a local override. Run `/status` and read the `Setting sources` line. `Enterprise managed settings` means only the administrator can change that key; `Command line arguments` means the `--settings` value passed at launch sets it.

  • Setting sandbox.enabled in managed settings stops developers adding allowed domains.
  • failIfUnavailable is harmless on native Windows laptops.
  • Strict sandbox mode also sandboxes commands developers type at the ! prompt.
  • A repository's excludedCommands still apply under an admin-required sandbox.
  • allowManagedDomainsOnly keeps a prompt for hosts outside the managed list.

Assumes Claude Code 2.1.286; the admin-required sandbox that ignores a repository's loosening settings requires 2.1.285 or later.