Skip to main content

Sandbox

The sandbox runs Bash commands inside a wall that the operating system enforces. It limits which files a command can write and which hosts it can reach, even when a permission rule allows the command. Permission rules decide whether a call runs. The sandbox limits what the call can touch once it runs.

The sandbox works on macOS, Linux, and WSL. sandbox.enabled turns it on, and it is false by default. Without its dependencies, a warning shows and commands run unsandboxed. The sandbox key works in any settings scope, but some keys work only in managed or user settings.

Example​

~/.claude/settings.json
{
"sandbox": {
"enabled": true,
"failIfUnavailable": true,
"network": {
"allowedDomains": ["github.com", "*.npmjs.org"]
},
"filesystem": {
"allowWrite": ["~/.cache/build"],
"denyRead": ["~/.ssh"]
}
}
}

Bash runs in the sandbox, reaches only those two hosts, can also write to the cache folder, and cannot read ~/.ssh. Claude Code exits at startup if the sandbox cannot start.

Core Keys​

Official pages: Configure the Sandboxed Bash Tool and Settings Reference.

KeyStatusWhat it doesHow it worksScope
sandbox.enabledDocumentedRuns Bash in the sandboxDefault false. Without dependencies, a warning shows and commands run unsandboxedEach scope
sandbox.failIfUnavailableDocumentedExit at startup if the sandbox cannot startDefault false. For managed hard gatesEach scope
sandbox.autoAllowBashIfSandboxedDocumentedAuto-allows sandboxed commandsReason text Auto-allowed with sandbox. Default true per the filesystem.disabled textEach scope
⚠️ sandbox.allowUnsandboxedCommandsDocumentedLets a call use dangerouslyDisableSandboxDefault true. When false, the parameter is ignored. A false from managed, --settings, or user settings holdsEach scope
sandbox.excludedCommandsDocumentedPatterns that run outside the sandboxBash rule syntax. A convenience, not a boundary: the permission flow still applies. Only managed, --settings, and user entries countMerged
sandbox.ignoreViolationsDocumentedMap of command patterns (* for all) to paths whose violations are not reportedMerged across scopesEach scope
sandbox.enableWeakerNestedSandboxDocumentedLinux: no fresh /proc mountFor hosts like unprivileged Docker. Reduces security. Default falseEach scope
sandbox.enableWeakerNetworkIsolationDocumentedmacOS: allow com.apple.trustd.agentFor Go tools with a MITM proxy. Reduces security. Default falseEach scope
sandbox.allowAppleEventsDocumentedmacOS: allow Apple EventsNeeded for open and osascript. Removes code-execution isolation. Default falseUser, managed, --settings
sandbox.ripgrep.command, sandbox.ripgrep.argsUndocumentedCustom rg for bundled ripgrep supportStringsUser, managed, --settings
sandbox.bwrapPathDocumentedLinux and WSL: path to bwrapAbsolute path. Overrides PATH detectionManaged only
sandbox.socatPathDocumentedLinux and WSL: path to socatAbsolute pathManaged only

Network Keys​

KeyStatusWhat it doesHow it worksScope
sandbox.network.allowedDomainsDocumentedDomains reachable without a promptWildcards like *.example.com. Merged with WebFetch(domain:...) allow rulesMerged
sandbox.network.deniedDomainsDocumentedDomains always blockedWins over allowedDomains. Merged from all scopesMerged
sandbox.network.allowManagedDomainsOnlyDocumentedOnly managed domains countDenied domains still come from all scopesManaged only
sandbox.network.strictAllowlistDocumentedDeny hosts not in allowedDomains without a promptNot for in-process tools like WebFetch. WebFetch rules leave the allowlistUser, managed, --settings
sandbox.network.allowUnixSocketsDocumentedmacOS: socket paths to allowIgnored on LinuxMerged
sandbox.network.allowAllUnixSocketsDocumentedAllow all Unix socketsBoth platformsEach scope
sandbox.network.allowLocalBindingDocumentedmacOS: bind to localhost portsBooleanEach scope
sandbox.network.allowMachLookupDocumentedmacOS: extra XPC or Mach namesTrailing * prefix match. For iOS Simulator or PlaywrightMerged
sandbox.network.httpProxyPort, sandbox.network.socksProxyPortDocumentedUse your own proxyLocal TCP portEach scope
🧪 sandbox.network.tlsTerminate.caCertPath, .caKeyPathGatedExperimental TLS terminationLets the filter see HTTPS bodies. Omit both for an ephemeral CA. Gate: marked [EXPERIMENTAL]User, managed, --settings

Filesystem Keys​

KeyStatusWhat it doesHow it worksScope
sandbox.filesystem.allowWriteDocumentedExtra writable pathsRepo-committed entries are limited to trusted tiersMerged
sandbox.filesystem.denyWriteDocumentedPaths denied for writes-Merged
sandbox.filesystem.denyReadDocumentedPaths denied for reads-Merged
sandbox.filesystem.allowReadDocumentedRe-allows reads inside denyReadWins over denyReadMerged
sandbox.filesystem.allowManagedReadPathsOnlyDocumentedOnly managed allowRead pathsBooleanManaged
sandbox.filesystem.disabledDocumentedSkip filesystem isolationmacOS and Linux and WSL only. Network and seccomp stay. Ignored on native Windows. Pinned to managed when managed sets filesystem rulesUser, managed, --settings

Credential Keys​

These keys hide secrets from commands. A command sees a placeholder, and the proxy swaps in the real value only for the hosts you name.

KeyStatusWhat it doesHow it worksScope
sandbox.credentials.files[]DocumentedProtects credential files or directoriesFields path, mode (deny or mask), extract, onExtractNoMatch (warn, deny, error), decode (jwt), maskClaims, maskDuplicates, injectHosts.Merged
sandbox.credentials.envVars[]DocumentedProtects environment variablesFields name, mode, extract, onExtractNoMatch, decode, maskClaims, injectHosts. extract and decode cannot combineMerged
sandbox.credentials.allowPlaintextInjectDocumentedSentinel swap on the plain HTTP pathDefault falseUser, managed, --settings
sandbox.credentials.awsPairsDocumentedGroups masked env vars into AWS pairs for SigV4 re-signingThe standard AWS trio pairs by itselfUser, managed, --settings
sandbox.credentials.sigv4DocumentedPolicy for SigV4 shapes the proxy cannot re-signdeny (default) or passthroughUser, managed, --settings

Environment Variables​

Source: the program. See also Environment Variables.

VariableStatusWhat it doesHow it worksScope
CLAUDE_CODE_BASH_SANDBOX_SHOW_INDICATORUndocumentedShows SandboxedBash as the tool nameTruthy value, for sandboxed callsEnv
IS_SANDBOXUndocumentedMarks a host that is already a sandboxSkips the sandbox gate when truthyEnv
CLAUDE_CODE_SANDBOXEDUndocumentedTreats the folder as trustedSkips the trust dialog checkEnv
CLAUDE_CODE_SANDBOX_LEAVE_PARENT_FOLDERS_ALONEUndocumentedWindows: skip the parent-folder grantsBooleanEnv
CLAUDE_CODE_SANDBOX_LEAVE_DENIES_TO_SRT_WINUndocumentedWindows: leave the deny lists to sandbox-runtimeBooleanEnv

Other Behavior​

  • The Bash tool takes dangerouslyDisableSandbox: true. The tool prompt tells the model to use it only after a violation that blocks the task. sandbox.allowUnsandboxedCommands: false ignores it.
  • A call with allowed_domains goes to the auto mode classifier. Allow rules do not approve those hosts.
  • The sandbox creates empty placeholder files such as .mcp.json in places where none exists.
  • Since 2.1.304, sandboxed commands start on Linux when a sandbox.filesystem.denyRead glob has brackets that are not a character class, such as a [user-id] route folder. Source: the release notes.
  • Linux ignores glob patterns in Edit and Read rules for the sandbox, and shows a warning.

Source for all four: the program prompt and warning texts.

How It Works​

With sandbox.autoAllowBashIfSandboxed on, a sandboxed command skips the prompt. See Permission Flow.