Claude Code ships an OS-enforced sandbox for shell commands, and it is off by default. Turning it on changes two things at once: where the agent can write, and whether it can reach the network at all. It also leaves a few doors open that surprise people, because the sandbox covers shell commands and not every tool.

Here is what the docs say, and what to check after you flip it.

What the sandbox covers

Shell commands only. On macOS, Linux and WSL2 the sandbox is OS-enforced. On native Windows, commands run unsandboxed.

With it on, writes are limited to the working directory, a temp directory, and any directories you add. Reads are broader: most of the machine, including ~/.ssh and ~/.aws/credentials, unless you add denyRead rules.

What happens to the network

There is no direct route out. Traffic goes through a local proxy that checks hosts against an allowed-domains list, and that list starts empty. An empty allowlist plus a proxy means the default is "nothing leaves", which is the right default for a coding agent you just pointed at a client repo.

The part people miss

The sandbox covers shell commands. Read, Edit, Write, WebFetch, WebSearch, MCP servers and hooks run outside it and follow permission rules instead. So a curl in Bash is bounded by the proxy, but the same request through WebFetch or an MCP server is governed by permissions.allow / ask / deny, not by the sandbox.

Two smaller details from the same docs: rules are evaluated deny, then ask, then allow, and the first match wins. And defaultMode values auto and bypassPermissions are ignored when they come from project or local settings, so a repo cannot quietly raise its own permissions.

A starting settings.json

{ "permissions": { "defaultMode": "default", "deny": ["Bash(git push *)", "Read(./.env)"] }, "sandbox": { "enabled": true, "network": { "allowedDomains": [] } } } 

Save it as .claude/settings.json for the project or in your user settings for everything. Then test it rather than trusting it: run a command that writes outside the working directory, and one that fetches a URL, and confirm both fail. An empty allowedDomains should stop the second one at the proxy.

Why deny rules go in permissions, not the sandbox

Because the Read tool is not inside the sandbox. A .env deny belongs on the Read tool. A git push deny belongs on Bash. If you put both in one place expecting the sandbox to enforce them, one of them silently does nothing.

Check the rest of your setup too

If you run more than one coding agent, the defaults differ enough to matter. Codex CLI is sandboxed by default in workspace-write mode with network off; Gemini CLI needs sandboxing switched on and its default macOS profile allows network; nono enforces a filesystem boundary but allows network unless you pass --block-net. I keep a dated, source-linked comparison of nine of them, with the vendor doc behind every row:

This is information about documented behavior, not security advice, and no setting here guarantees safety. Docs change; the comparison carries the date each row was read.