Claude Code Sandbox: How to Keep It From Wrecking Your Mac

Claude Code has a built-in sandbox, but it’s off until you turn it on. Type /sandbox in a session, pick a mode, and every shell command Claude runs is fenced in by macOS itself: it can write to your project folder and not much else, and it can’t reach the internet unless you allow the site.

That’s the short answer. The catch is what the sandbox doesn’t cover, and that’s the part most people miss.

I run Claude Code agents on a Mac Mini at home that works as an always-on worker, so I care a lot about what it can and can’t touch while I’m not looking. Here’s how the sandbox works, how to set it up on a Mac, and when you need something stronger.

What the Claude Code sandbox actually does

The sandbox wraps the shell commands Claude runs, plus any process those commands start. On a Mac it uses Seatbelt, the sandbox framework built into macOS. On Linux and WSL2 it uses bubblewrap. Native Windows isn’t supported, so commands there run unsandboxed unless you move Claude Code into WSL2.

Because the operating system enforces the limits, Claude Code can let sandboxed commands run without asking you to approve each one. That’s the real selling point for you. Fewer prompts, and a wall behind them.

Out of the box, the walls look like this:

AccessDefault inside the sandbox
Writing filesYour current project folder and its subfolders, folders you add with /add-dir, and your temp folder
Protected filesStill blocked even inside the project: .claude settings, .mcp.json, .bashrc and .zshrc, .gitconfig, and git hooks and config
Reading filesMost of the machine, including ~/.ssh and ~/.aws/credentials, unless you restrict it
NetworkNothing gets out directly. Traffic goes through a local proxy, and the allowed list starts empty

Look at that reading row again. By default a sandboxed command can still read your SSH keys, your cloud logins, pretty much anything in your home folder. It just can’t send them anywhere you haven’t allowed. If you want those files off limits, you have to say so (the settings below do).

How to turn on the sandbox on a Mac

On macOS there’s nothing extra to install. Seatbelt is already there.

  1. Open your project folder in the terminal and start Claude Code with claude.
  2. Type /sandbox. A panel opens with a few tabs.
  3. On the Mode tab, pick auto-allow (sandboxed commands run with no prompt) or regular permissions (every command still asks, sandbox or not). Your pick saves to .claude/settings.local.json for that project only.
  4. On the Overrides tab, turn on strict sandbox mode. That stops Claude from retrying a failed command outside the sandbox.
  5. Test it. Ask Claude (don’t type it yourself at the ! prompt, since those usually run unsandboxed) to run touch ~/sandbox-probe. On a Mac you should get “Operation not permitted.”
  6. Ask it to run curl --noproxy '*' https://example.com. You should see “Could not resolve host.”

If both fail the way they should, the sandbox is working.

Turn it on for every project

The /sandbox panel only covers the project you’re in. To make it the rule everywhere, put it in your user settings at ~/.claude/settings.json. Here’s a starting point built from the documented keys:

{
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false,
    "autoAllowBashIfSandboxed": true,
    "filesystem": {
      "denyRead": ["~/.ssh", "~/.aws"]
    },
    "network": {
      "allowedDomains": ["github.com", "*.npmjs.org"],
      "strictAllowlist": true
    }
  }
}

What each line is doing for you:

  • enabled turns it on.
  • failIfUnavailable makes Claude Code refuse to start if the sandbox can’t run. Without it, Claude Code quietly runs commands unsandboxed instead, which is exactly what you don’t want.
  • allowUnsandboxedCommands: false is strict mode. Claude ignores its own request to retry a command outside the walls.
  • autoAllowBashIfSandboxed is already true by default. Set it to false if you’d still like a prompt for every command.
  • denyRead keeps your SSH and AWS keys out of reach.
  • allowedDomains is your network allowlist. Add only what your project really needs.
  • strictAllowlist refuses any site that isn’t on the list instead of asking you. That one matters more than it looks, because in bypass mode a site outside the list is allowed with no prompt at all.

One small trap: sandbox paths use normal conventions, so ~/.ssh means your home folder. Claude Code’s permission rules use a different style (//path for absolute paths). Don’t copy a path from one into the other without checking.

What the sandbox does not protect

This is the part that matters most, so read it twice.

The sandbox only covers shell commands. Claude’s own file tools, its web tools, MCP servers and hooks all run outside it. So if Claude edits a file with its Edit tool, the sandbox isn’t what stops it. Your Claude Code permissions are.

A few more gaps worth knowing:

  • Anything in excludedCommands runs with full access, no file or network limits. A broad pattern there can let Claude write a script and then run it outside the sandbox.
  • Commands you type yourself at the ! prompt usually skip the sandbox.
  • Docker commands fail inside it. The fix is an excludedCommands entry like docker compose *, which, again, runs with full access.
  • On a Mac, git over SSH fails. Switch the remote to HTTPS.
  • Tools that ignore proxy settings, like plain ssh and most database drivers, can’t connect at all.

None of that makes the sandbox useless. It makes it one layer.

Sandbox vs. dev container vs. VM

Want a wall around everything Claude Code does, including its file tools? You’ve got a few options. Here’s how Anthropic’s own comparison breaks down:

OptionWhat it walls offNeeds Docker?Setup
Built-in sandbox (/sandbox)Shell commands and what they startNoMinimal on a Mac
Sandbox runtime (srt claude)The whole Claude Code process, including file tools, MCP servers and hooksNoLow
Dev containerA full development environmentYesMedium
Virtual machineA full operating systemNoHigh

For everyday work on your own Mac, the built-in sandbox is the right start. You get fewer prompts and a real limit on your shell commands.

The sandbox runtime is the open source @anthropic-ai/sandbox-runtime package. You install it with npm, write a settings file, and launch Claude Code through it with srt claude. It’s labeled a beta research preview, so expect the config format to change.

A dev container runs Claude Code inside Docker with your project mounted in. Anthropic publishes a reference dev container with a firewall script that blocks outbound traffic except to the sites it allows. Even then, the warning is blunt: in skip-permissions mode, a malicious project can still steal anything inside the container, including your Claude Code login. So only use it with code you trust, and don’t mount your SSH keys into it.

If you run skip-permissions mode, read this

I’ve run Claude Code in its skip-permissions (bypass) mode for speed. It’s fast. It’s also the mode where nothing asks you before a command runs.

Here’s the line from Anthropic you should take seriously: always run --dangerously-skip-permissions sessions inside a container, a VM or the sandbox runtime, so everything Claude Code runs is inside the boundary too. The built-in Bash sandbox by itself isn’t enough for unattended runs, because it only covers shell commands.

What I do on top of that: I keep backups before edits, and I give the agent scoped helper scripts for the risky jobs instead of letting it hand-build commands against live systems. A script that can only do one thing is a lot harder to misuse than a raw shell.

Why bother? In April 2026, a startup founder said a Cursor coding agent deleted his production database and its backups on Railway in a single API call, in nine seconds. A strict network allowlist is the kind of wall that refuses a shell command calling a host you never approved. A backup stored somewhere else would have made it a bad afternoon instead of a disaster.

So back up the Mac first. Time Machine is already on your Mac and only needs an external drive. If you’re going to leave an agent running on an always-on Mac Mini like mine, it matters even more, because nobody’s watching when something goes wrong.

Bottom line: turn on /sandbox, set failIfUnavailable and strict mode, block reads of your keys, and keep the network list short. If you go hands-off with bypass mode, put the whole thing in a container or VM.

FAQ

Is Claude Code sandboxed by default?

No. The sandbox is off until you turn it on with /sandbox or set sandbox.enabled to true in your settings.

Does the sandbox stop Claude from reading my SSH keys?

Not by default. Sandboxed commands can read most of the machine, including ~/.ssh. Add those folders to sandbox.filesystem.denyRead, and add a Read deny rule in your permissions so Claude’s own file tools can’t read them either.

Does the Claude Code sandbox work on Windows?

Only inside WSL2. On native Windows, commands run unsandboxed. WSL1 isn’t supported.

Do I still need a dev container if I use the sandbox?

For normal work with prompts on, the sandbox is plenty. For unattended runs with skip-permissions, yes: use a dev container, a VM or the sandbox runtime so everything Claude Code does is inside the wall.

Want this done for you?

I run Claude Code on my own Mac Mini, and I’m putting together a done-for-you setup for people who’d rather not spend a weekend locking it down. Join the waitlist and I’ll email you when spots open.

    No spam. One email when spots open.

    Running a business and want AI doing more of your marketing? See AI consulting.

    Brian Meiggs
    Brian Meiggs
    Brian Meiggs is the founder of MeiggsMedia, a digital publishing and performance marketing company. He has spent over a decade helping readers take control of their money, and personally signs up for and cashes out from the apps and financial products his sites cover, then writes up what actually paid. He was named to the Northern Virginia 40 Under 40 in 2026. His work has been featured in the Wall Street Journal, Business Insider, Entrepreneur, and Yahoo Finance.
    Tuesday, November 24, 2026

    SHARE

    Like the article? Share it with friends on your favorite platform.

    MEIGGSMEDIA

    -Advertisement-

    Related

    OpenClaw Security: The Real Risks and How to Lock It Down

    What has actually gone wrong with OpenClaw so far, and the exact settings, audit commands and habits that lock it down.

    How to Set Up OpenClaw on a Mac Mini (Safely)

    A step-by-step guide to installing OpenClaw on a Mac Mini as an always-on assistant, with the settings that keep it from becoming someone else's.

    Backblaze Review (2026): Worth It for Your Mac?

    Backblaze is worth it for most Mac owners, as long as you turn on the free one-year version history. Here's what it does well, where it falls short, and how it fits a Mac that runs AI agents.