D3 · Claude Code › Cluster 3 · Permissions & Safety

3.4 · Sandboxing & Bypassing Prompts

Safe autonomy

CONCEPT Two very different ways to cut prompts

Both reduce permission prompts, but they are opposites in safety. The exam turns on telling them apart:

Sandbox (/sandbox)--dangerously-skip-permissions
What it controlsWhat a Bash command can access once it runsWhether each tool call runs at all
Enforced byThe operating system (Seatbelt / bubblewrap)Nothing — checks are skipped
Replaces the prompt withThe sandbox boundary itself (auto-allow mode)Nothing at all
Prompt-injection protectionYes — OS boundary holds even if the model is fooledNone

The sandboxed Bash tool lets Claude run most shell commands without asking, because you instead define which files and network domains commands may touch and the OS enforces that boundary for every Bash command and its child processes. Enable it with /sandbox; it runs on macOS (Seatbelt), Linux, and WSL2 (bubblewrap + socat). Native Windows is not supported.

CONCEPT When bypassing prompts is acceptable — and when it's reckless

--dangerously-skip-permissions (equivalently --permission-mode bypassPermissions) skips prompts and safety checks. It offers no protection against prompt injection or unintended actions.

✅ Acceptable: isolated containers, VMs, or dev containers — ideally without internet access — where Claude Code cannot damage your host or exfiltrate data. This is the CI / ephemeral-agent case. Claude Code even refuses to start this mode as root/sudo on Linux/macOS unless it detects a recognized sandbox.
🚫 Reckless: on your real workstation with your real credentials and network. A single prompt-injection payload in a file, web page, or dependency can then run destructive or exfiltrating commands with zero confirmation. For "far fewer prompts with safety checks," use auto mode instead — it keeps a background classifier reviewing actions.
⚠️ Even in bypassPermissions, explicit ask rules still force a prompt, and removals targeting the filesystem root or home (rm -rf /, rm -rf ~) still prompt as a circuit breaker against model error.

DIAGRAM Layers of defense in depth

flowchart TD A["Claude wants to run a Bash command"] --> P{"Permission layer:
deny / ask rules?"} P -->|"deny"| STOP["🔴 Blocked before it runs"] P -->|"ask"| PR["🟠 Prompt (even if sandboxed)"] P -->|"allowed / auto-allow"| S{"Sandbox enabled?"} S -->|"yes"| OS["🟢 Runs, but OS confines FS + network
holds even under prompt injection"] S -->|"no + bypassPermissions"| RAW["🔴 Runs with full host access
no injection protection"] classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef gate fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; classDef bad fill:#f8d7da,stroke:#dc3545,color:#721c24; class OS ok; class PR gate; class STOP bad; class RAW bad;

CODE Enabling and shaping the sandbox

# Turn the sandbox on for the current project (panel: Mode / Overrides / Config)
/sandbox

# Enable across all your projects + grant a couple of write paths, in settings.json
{
  "sandbox": {
    "enabled": true,
    "filesystem": {
      "allowWrite": ["~/.kube", "/tmp/build"],
      "denyRead": ["~/.ssh", "~/.aws"]
    },
    "network": {
      "allowedDomains": ["registry.npmjs.org", "*.github.com"]
    }
  }
}

# Container / CI only: skip prompts entirely (no injection protection)
claude --dangerously-skip-permissions
🔑 Sandbox restrictions are enforced at the OS level, so they apply to all subprocesses a command spawns (kubectl, terraform, npm), not just Claude's own file tools. Sandbox filesystem paths use standard prefixes (/abs, ~/home), which differ from Read/Edit rules' //abs convention.

TRADE-OFFS Sandbox auto-allow vs. skip-permissions

✅ Sandbox (auto-allow)

  • Fewer prompts and a real OS-enforced boundary
  • Survives prompt injection — a fooled model still can't leave the box
  • Deny/ask rules and rm -rf / circuit breakers still apply

🚫 --dangerously-skip-permissions

  • Zero prompts, zero safety checks, no injection protection
  • Broad allowedDomains (e.g. github.com) can still enable exfiltration paths
  • Only safe in throwaway containers/VMs, ideally offline

EXAM TRAPS

Trap: "/sandbox is a permission mode." → It isn't. Permission modes decide whether a call runs and whether you're prompted; the sandbox restricts what a Bash command can access once it runs. They compose.
Trap: "--dangerously-skip-permissions is fine as long as I'm careful." → It offers no protection against prompt injection or unintended actions. Reserve it for isolated containers/VMs; on a real machine, prefer auto mode or the sandbox.
Trap: "The sandbox blocks reading my SSH keys by default." → No. The default read policy still allows reading ~/.ssh and ~/.aws/credentials. You must add them to denyRead (or use sandbox.credentials) to block them.
Trap: "Allowing github.com in the sandbox is safe." → Broad domains can create data-exfiltration paths; the proxy decides from the client-supplied hostname without inspecting TLS, so techniques like domain fronting can slip out. Allow only trusted domains.

PRACTICE

Q1 · Why does the sandbox protect against prompt injection while --dangerously-skip-permissions does not?

The sandbox boundary is enforced by the operating system on the running process, so it holds regardless of what the (possibly manipulated) model chose to run. Skip-permissions removes checks entirely, so a fooled model's command executes with full host access.

Q2 · A test suite needs to reach registry.npmjs.org under the sandbox but keeps prompting. Fix?

Pre-allow the domain: add registry.npmjs.org to sandbox.network.allowedDomains. Otherwise the first request to each new domain prompts for approval.

Q3 · When is --dangerously-skip-permissions the right call?

In an isolated, disposable environment — a container, VM, or dev container, ideally without internet — such as CI or an ephemeral agent, where Claude Code can't damage your host or leak data. Never on a workstation with real credentials and network access.