Claude Code & Context Engineering

Claude Code Permissions and Sandboxing: Permission Modes, Allowlists and Safe Autonomy

29 September 2026 · Updated 28 November 2026 · 13 min read · by Yang Kai

How Claude Code permission modes, allowlists and sandboxing actually work together — plus a permission policy template by project type so autonomy stays safe.

Template inside: Permission policy template by project type

Contents
  1. Layer 1: permission modes set the posture
  2. Layer 2: allow, ask and deny rules are the standing policy
  3. Layer 3: the sandbox limits what approval can reach
  4. Permission policy by project type
  5. A sane setup sequence

Safe autonomy in Claude Code comes from configuring three layers before the session starts: the permission mode that sets the default posture, the allow, ask and deny rules that pre-decide the commands you trust and the ones you never will, and the sandbox that limits what an approved shell command can actually reach. Set all three deliberately and you can let the agent run for an hour without either babysitting it or worrying about it.

The reason to decide in advance is prompt fatigue. Anthropic’s engineering team has reported that developers approve the overwhelming majority of permission prompts — 93% in the figure it published when introducing the sandbox. A prompt you approve without reading is not a safety check; it is a delay. The fix is to move the decisions you make the same way every time into configuration, and keep the prompts for the decisions that genuinely need a human in the moment.

This article goes through the three layers in order: the six permission modes and what each one actually lets through, the rule system that overrides them, and the sandbox underneath both — all checked against Anthropic’s permissions and sandboxing documentation in November 2026. It ends with the artefact: a permission policy you can copy per project type.

The three layers at a glance:

Layer What it decides Where it lives
Permission mode The default answer when no rule matches Session, --permission-mode, or defaultMode in settings
Allow / ask / deny rules Specific tools, commands and paths, decided in advance permissions in settings.json files
Sandbox What an approved shell command can reach on disk and network sandbox in settings.json, or the /sandbox command

Layer 1: permission modes set the posture

A permission mode answers one question: when the agent wants to do something no rule has pre-approved, what happens by default? Claude Code has six modes:

Mode What runs without asking Use it for
default (shown as Manual) File reads in the working directory, and anything an allow rule covers Unfamiliar code, production-adjacent work, learning a repo
plan Nothing that changes files — the agent explores and produces a plan Big changes where you want to approve the approach first
acceptEdits File edits and common file commands (mkdir, mv, cp, rm, sed) inside the working directory Familiar code you will review as a diff afterwards
auto Almost everything — a separate classifier model reviews commands and network access and blocks what looks out of bounds Everyday work with far fewer prompts; the starting mode for interactive sessions in current versions when nothing is configured
dontAsk Only what needs no approval, plus allow-listed actions; everything else is denied rather than asked CI and other unattended runs, where nobody can answer a prompt
bypassPermissions Everything, with no checks Disposable containers and VMs only

You switch modes with Shift+Tab during a session, choose one at launch with claude --permission-mode acceptEdits, or set the starting mode for a project with defaultMode inside the permissions block of its settings file. One deliberate friction worth knowing: bypassPermissions set in a project’s settings file does not take effect — a repo you clone cannot talk you into the most permissive mode by itself.

The mistake to avoid is choosing the mode by mood: cautious on Monday because an article scared you, permissive on Friday because the prompts got annoying. Choose by project, write it into the project settings, and let the repo carry the decision. A personal blog and a client codebase with deployment keys should never share a posture.

Layer 2: allow, ask and deny rules are the standing policy

Rules live in the permissions object of a settings.json file and match tool calls by pattern: Tool alone matches every use of that tool, and Tool(specifier) narrows it — Bash(npm run test:*) for a command prefix, Read(./.env) for a path. A path rule written for Edit governs all the built-in writing tools, including Write. In path patterns, a leading / anchors at the working directory, // at the filesystem root, and ~/ at your home directory.

{
  "permissions": {
    "defaultMode": "acceptEdits",
    "allow": [
      "Bash(npm run test:*)",
      "Bash(npm run build)",
      "Bash(git status)",
      "Bash(git diff *)"
    ],
    "ask": [
      "Bash(git push *)"
    ],
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Bash(rm -rf *)",
      "Bash(git push --force *)"
    ]
  }
}

Three mechanics decide how rules behave, and all three are easy to get wrong:

Evaluation order is fixed: deny, then ask, then allow. The first match in that order wins, and specificity does not change it. A broad deny beats a narrow allow for the same command, every time. That is the safe direction for the order to fail in — but it means you cannot carve exceptions out of a deny rule with a clever allow rule.

Rules merge across settings files. Most settings override each other down the chain — managed settings from an administrator, then .claude/settings.local.json (your personal overrides for one project), then .claude/settings.json (the project’s shared, committed policy), then ~/.claude/settings.json (your policy everywhere). Permission rules instead accumulate: a deny written at any level is in force at every level, and no allow elsewhere can reopen it.

Permissions are enforced by Claude Code, not by the model. A line in CLAUDE.md telling the agent to stay away from a file is guidance the model usually follows; a deny rule is a control the harness applies regardless. Anything that must never happen belongs in a rule, not in a prompt. Hooks can add finer-grained, programmatic decisions on top — the hooks deep dive covers that layer — but rules are the standing policy hooks operate inside.

Rules are not only for Bash and files. A WebFetch rule can be scoped to a domain, so documentation sites you trust load without a prompt while unknown hosts still ask. MCP tools follow the same pattern: an allow rule names the server and the tool — mcp__<server>__<tool> — which means you can pre-approve one read-only tool from a server without pre-approving everything that server offers. Treat each MCP tool with the same suspicion as a shell command, because functionally it is one: code run on your machine, with your credentials, at the agent’s request.

Two working principles keep a rule set healthy. Allow the boring and specific: your build, test and lint commands, read-only git inspection, formatting — run dozens of times a week, effectively irreversible-proof, and each one you pre-approve is one less prompt training you to click yes. Never allowlist a shell escape hatch: a rule that approves a general-purpose interpreter or an unrestricted shell pattern approves everything that tool can do, which is everything. If a command needs that breadth, it should ask — every time. The /permissions dialog shows every rule in force and which file it came from, and it is where approvals you grant with “don’t ask again” are saved.

One guard sits in front of project rules specifically: the allow rules and extra directories in a repo’s .claude/settings.json only apply after you accept the workspace trust dialog for that folder. That ordering is deliberate — a cloned repo cannot pre-approve its own commands on your machine before you have agreed to trust it. For teams, an administrator can go further with managed settings, deployed outside the repo entirely, which neither project nor user settings can loosen. That is the layer to use for rules that must hold even on a machine you do not control.

Deny rules have one documented gap you should know about. They cover Claude’s built-in file tools and the shell file commands Claude Code recognises, such as cat, head, tail, sed and tee. They do not cover a command that reads a file without naming it — a recursive grep -r from the project root — or a script that opens the file itself. That gap is exactly what the third layer is for.

Layer 3: the sandbox limits what approval can reach

Permissions decide what the agent may attempt. The sandbox decides what an attempt can reach — and it is enforced by the operating system, not by Claude Code’s own checks. On macOS it uses the built-in Seatbelt framework; on Linux and WSL2 it uses bubblewrap and socat. On native Windows, commands run unsandboxed, so the sandbox route there is to run Claude Code inside WSL2.

The scope matters: the sandbox wraps shell commands — Bash, PowerShell and Monitor commands, and every process they start. Claude’s own file tools, MCP servers and hooks run outside it, which is why the sandbox complements deny rules rather than replacing them. It is off by default; turn it on with /sandbox in a session or in settings:

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

The defaults inside the sandbox, per Anthropic’s sandboxing documentation:

Access Default for a sandboxed command Setting that changes it
Writes The working directory, a per-user temp directory, and directories you have added filesystem.allowWrite, filesystem.denyWrite
Reads Most of the machine — including ~/.ssh and ~/.aws/credentials filesystem.denyRead, the credentials block
Network No direct route out; a local proxy checks each host against an allowlist that starts empty network.allowedDomains, network.deniedDomains
Environment Inherited from Claude Code, secrets included The credentials block, CLAUDE_CODE_SUBPROCESS_ENV_SCRUB

Two settings decide how the sandbox feels day to day. With autoAllowBashIfSandboxed on, a command that fits inside the boundary runs without a prompt, and only a command that needs to escape it falls back to the normal permission flow — when Anthropic introduced the sandbox in October 2025, it reported an 84% reduction in permission prompts in its own internal use. And allowUnsandboxedCommands: false closes the fallback entirely, so a command that cannot run inside the boundary does not run at all — the right setting for unattended work.

Note the read default before you rely on the sandbox for secrets: reads are broad by design, so add denyRead entries or a credentials block for ~/.ssh, ~/.aws and anything similar on day one. For commands launched through MCP servers — which run outside the sandbox — the equivalent scrutiny is in the MCP security checklist.

Permission policy by project type

Decision Personal site / blog Client or team repo Production-adjacent
Default mode acceptEdits or auto auto or default, agreed by the team in shared settings default (Manual); plan for changes
Allow build, test, lint, format, git status/log/diff Same, committed in the project’s shared settings Read-only inspection only
Deny .env reads, rm -rf, force push Same + deploy commands, schema migrations Same + all writes to infra/config paths
MCP servers Read/write for own content tools Team-approved servers only Read-only credentials, or none
Sandbox On, auto-allow mode On, writes limited to the project Required — plus a container for full autonomous runs
Review rhythm Skim the final diff PR review as normal Human reviews plan before, diff after

Use the table as a starting policy, then record your version in the project’s settings and, where a team shares the repo, put changes through the same review process you use for the shared team CLAUDE.md — permission changes are policy changes and deserve a second pair of eyes. The same defaults pair with the settings that cut cost to form the configuration layer; neither file should drift far from the other.

A sane setup sequence

  1. Write the deny list on day one, before the first long run, not after the first scare: secret files, destructive commands, force pushes.
  2. Start in default or auto for the first sessions on a new project and watch what you approve repeatedly. That list is your allowlist, earned from evidence rather than guessed — add it through /permissions or directly in settings.
  3. Turn the sandbox on and add denyRead for your credential directories, so the commands you have stopped prompting about are also fenced in.
  4. Widen autonomy one project at a time, and narrow it instantly and without embarrassment whenever the agent surprises you. A permission you re-grant next week costs a minute; an action you could not undo costs considerably more. Inside a sandbox with a deny list underneath it, freer modes stop being reckless — which is also the precondition for running Claude Code unattended in CI, where no human is present to answer prompts at all. If you are packaging a repeatable setup for others, these defaults are the layer we consider non-negotiable in the Claude Code Workflow Pack.

FAQ

What is the difference between an allowlist and a permission mode in Claude Code? The mode sets the default for anything no rule covers — ask, allow edits, let a classifier decide, deny, or bypass. The rules carve out specific decisions in advance: commands and paths you have pre-approved, pre-questioned or pre-denied regardless of the default. Modes are posture; rules are policy.

Is bypassPermissions ever a reasonable choice? Yes — inside a genuinely isolated environment such as a disposable container or a dedicated CI runner, combined with an explicit deny list. Claude Code itself refuses to start in that mode as root or under sudo outside a recognised sandbox. On a workstation holding your real credentials and unrelated projects, it trades a small convenience for an unbounded blast radius.

Should my rules live in user settings or project settings? Project settings for anything repo-specific, so the policy travels with the code and a team shares it. User settings are for the handful of commands you trust everywhere, on every project, without exception. Remember that deny rules merge across both: a personal deny still applies inside a permissive project.

Does the sandbox replace permission rules? No. Sandboxed commands still pass through the permission flow unless auto-allow is on, and the sandbox covers shell commands only — file tools, MCP servers and hooks run outside it. Rules decide what may be attempted; the sandbox limits what an attempt can reach. You want both.

Can CLAUDE.md change what Claude Code is allowed to do? No. Permission rules are enforced by Claude Code itself, not by the model, so instructions in CLAUDE.md or a prompt can shape what the agent tries but never what it is allowed. Anything that must be guaranteed belongs in a deny rule or the sandbox. The event-by-event hooks guide covers the closest thing to programmable exceptions.

Learn more:

Category: Claude Code & Context Engineering · Tags: #claude-code #security #ai-coding

Next step: this article is part of Claude Code guides, which covers the full topic from first setup to advanced use.

Related guides