Claude Code

Sandboxing and isolation

Bash sandbox, full-process runtime, dev containers, Docker, VMs, hosted execution, permissions, networking, and credentials.

Permissions decide whether a command may execute; isolation limits the files, networks, and credentials it can reach afterward. Consider both for automatic execution and unfamiliar repositories.

Sandboxing does not change model data flow. Read prompts/files still go to Anthropic, Passion8, or the configured provider.

#Compare isolation options

OptionScopeDocker requiredUse
Bash sandboxShell commands and childrenNoFewer routine prompts
Sandbox runtimeEntire Code process, MCP, hooksNoFull-process isolation without Docker
Dev containerDevelopment environmentYesStandardized team/unattended work
Custom containerDevelopment environmentYesExisting CI/remote infrastructure
VMOperating systemNoUntrusted code or stronger boundaries
Hosted webAnthropic-managed VMNoDelegated browser/mobile work

The Bash sandbox does not include built-in Read/Edit, MCP servers, or hooks. Use a full-process runtime, container, or VM to include them.

#Relationship to permissions

LayerControlsConfiguration
RulesTools, paths, commands, domainspermissions.allow/deny
ModeApproval behaviordefault, plan, auto, bypass
SandboxPost-launch accesssandbox filesystem/network

Skipping permission prompts should be reserved for appropriate isolation. Auto mode's classifier is not an operating-system boundary.

#Enable the Bash sandbox

1

Open the panel

/sandbox

The panel shows Mode, Overrides, and Config. Linux/WSL2 checks bubblewrap and socat dependencies.

2

Choose a mode

Auto-allow automatically runs commands constrained by the sandbox. Regular permissions retains normal approval while still isolating execution.

3

Run a test command

Default writes are limited to the working directory and session temporary directory. New domains prompt. Disable unsandboxed fallback for a stricter boundary.

Linux/WSL2 dependencies:

sudo apt-get install bubblewrap socat

Fedora:

sudo dnf install bubblewrap socat

Native Windows does not support this Bash sandbox; use WSL2, containers, or a VM.

#Common settings

Require an available sandbox:

{
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false
  }
}

Allow selected write directories:

{
  "sandbox": {
    "enabled": true,
    "filesystem": {
      "allowWrite": ["~/.kube", "/tmp/build"]
    }
  }
}

Default reads may still reach home-directory credentials. Protect them explicitly:

{
  "sandbox": {
    "enabled": true,
    "credentials": {
      "files": [
        { "path": "~/.aws/credentials", "mode": "deny" },
        { "path": "~/.ssh", "mode": "deny" }
      ],
      "envVars": [
        { "name": "GITHUB_TOKEN", "mode": "deny" },
        { "name": "NPM_TOKEN", "mode": "deny" }
      ]
    }
  }
}

Credential masking can preserve authentication without exposing the real token, but requires supported TLS termination/domain policy. Configure it in user, CLI, or managed settings, not an untrusted project.

#Network control

A proxy controls command network access. New destinations normally require approval. Teams can define allowed domains and lock them with managed policy:

{
  "sandbox": {
    "network": {
      "allowedDomains": [
        "registry.npmjs.org",
        "*.github.com",
        "passion8.cc"
      ]
    }
  }
}

Use allowManagedDomainsOnly to prevent widening the managed list. Stronger enterprise inspection may require a custom TLS-terminating proxy; hostname allowlists alone do not inspect encrypted content.

#Enforced organization policy

MDM, system-managed, or server-managed settings can enforce:

{
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false
  }
}

Also consider:

  • Credential restrictions for SSH/cloud/package-manager secrets.
  • allowManagedReadPathsOnly to prevent local widening.
  • allowManagedDomainsOnly for network policy.
  • A minimal excludedCommands list.

See Enterprise administration.

#Common failures

SymptomAction
Host not allowedApprove/add the intended domain
Jest hangsTry --no-watchman
Docker failsDocker socket access weakens isolation; use deliberate exclusions plus outer isolation
macOS open/osascript failsApple Events blocked; review exclusions or allowAppleEvents carefully
Nested bubblewrap failsConsider weaker nested mode only when outer isolation provides the boundary
Permission bypass rejected as rootRun as a non-root user in the isolated environment

#Limits

  • Bash isolation does not cover built-in file tools, MCP, or hooks.
  • Broad network access increases exfiltration paths.
  • Writing PATH entries, shell configuration, or system directories weakens isolation.
  • Unix sockets, especially Docker, can bypass intended boundaries.
  • Computer use controls the real desktop outside the Bash sandbox.

Prefer containers/VMs for untrusted code. For routine prompt reduction, begin with sandbox auto-allow.

#Official references

Support

Need help?

For setup, billing, or model issues, email us. Check the status page for uptime.

WeChat / QQ support is available at the bottom right.