GuideAgentic ways of working · Intermediate

Permissions and safety: let agents act without losing control

Permission modes, allow, ask and deny rules, managed settings, the Bash sandbox, secrets, network egress and prompt-injection defences for Claude Code and similar agents, with safe default configurations you can copy.

Checked 13 Oct 202619 min read1 prompt2 hooks

On this page
  1. What it is
  2. When to use it
  3. Members only: Set it up step by step
  4. Members only: Defend agents that read the web or email
  5. Members only: Keep an audit trail
  6. Members only: Recipes
  7. Members only: Patterns that work
  8. Members only: Mistakes to avoid
  9. Members only: Exercises

An agent with a shell can do anything your account can. Three layers keep that power useful: permissions decide what the agent may attempt, the sandbox decides what an attempt can reach, and audit logs tell you what happened. Set up all three, because each one covers the others' blind spots.

What it is#

Claude Code checks every tool call against several layers. Only some of them are enforced:

LayerWhat it doesEnforced
Instructions (CLAUDE.md, the prompt)Tell the agent what you wantNo. The model tries to follow them
Permission modeSets what runs without askingYes
Allow, ask and deny rulesPre-approve, force a prompt or block specific callsYes. Deny wins in every mode
HooksYour script inspects each call and can block itYes, for the calls it sees
SandboxThe operating system limits which files and hosts shell commands can reachYes, for Bash and its child processes
Outer isolationA container, VM or dev container around the whole processYes, for everything inside it
Audit trailOpenTelemetry events and hook logs record decisionsRecords, does not block
1. Input A arrives: refund order 1042. 2. The typed decision model returns action refund with probability 0.93. 3. 0.93 is above the 0.8 threshold, so the refund runs automatically. 4. Input B arrives: refund three months of a plan. 5. The model returns probability 0.41, below the threshold. 6. B goes to a person to review, or to a safe fallback. 7. In shadow mode, candidate model v2 scores both inputs too. Its answers are logged beside the live ones and never acted on: it agrees on A and differs on B.Shadow modelogged, never acted onInput ARefund order #1042Typed decision modelaction: "refund"p: …threshold 0.8A 0.93B 0.41Runs automaticallyA: refund issuedPerson or fallbackB: in reviewCandidate v2same input, no action#1042 v1 0.93 v2 0.88agrees#1043 v1 0.41 v2 0.86differs

Claude Code has six permission modes. Press Shift+Tab to cycle through them in the CLI:

ModeRuns without askingUse it for
default (shown as Manual)Reads onlySensitive work, unfamiliar code
acceptEditsReads, file edits and common filesystem commands such as mkdir and mvIterating on code you review as it changes
planReads, plus classifier-approved commands when auto mode is availableExploring before any change
autoEverything, with a classifier model checking actions firstLong tasks where you trust the direction
dontAskReads in your working directories and pre-approved tools; everything else is deniedCI and scripts with an exact allowlist
bypassPermissionsEverythingIsolated containers and VMs only

With Claude Code v2.1.283 or later, auto is the starting mode for interactive terminal and VS Code sessions, on every plan. Its classifier blocks actions that go beyond your request, target infrastructure it does not recognize, or look driven by hostile content Claude read: piping a download into a shell, force pushes, production deploys, mass deletions, printing live credentials and dozens more. It also pauses and falls back to prompting after 3 blocks in a row or 20 in a session. It reduces prompts; it does not guarantee safety. claude -p and Agent SDK runs start in default in most setups.

Some things no mode approves on its own, not even bypass: calls matching an explicit ask rule, MCP tools their server marks as needing user interaction, and rm or rmdir aimed at critical paths such as /, your home directory or the working directory.

When to use it#

Match the setup to the job and the blast radius:

You want toStart withIsolation needed
Review every action yourselfclaude --permission-mode defaultNone
Fewer prompts while you watch, no classifierManual mode plus the Bash sandbox in auto-allow mode (/sandbox)The built-in sandbox on macOS, Linux or WSL2
Explore a codebase firstclaude --permission-mode planNone
Hands-off work on a trusted taskauto, the defaultA sandbox or container adds a second line
CI with an exact allowlistclaude -p "..." --permission-mode dontAsk --allowedTools "Bash(npm test)" "Read"Whatever your CI runner provides
Fully unattended runs--dangerously-skip-permissions as a non-root userRequired: a container, VM or the sandbox runtime

Agents that read the web, email or tickets need extra care, because the content itself can carry instructions. The members section gives the full defence; the short version is to keep secrets out of reach, put a person in front of anything that sends or deletes, and limit where the agent can send data.

Other agents follow the same pattern. Codex combines a sandbox mode (read-only, workspace-write with the network off by default, or danger-full-access) with an approval policy (on-request, never, or a granular policy per category). GitHub Copilot, Cursor and Gemini CLI each have their own approval settings. The ideas on this page carry over; the keys do not.

Set it up step by step

1. See what you already have - /permissions lists every allow, ask and deny rule and the settings file it came from. It also shows recent auto mode denials, where you can press r to retry one with a manual approval. - /status shows which ...

Members only below this line

Get the rest of this guide free

What you get on this page:

  • 1 prompt
  • 2 hooks

Free. You also get Stratiflux Weekly: one email a week, unsubscribe anytime.

Also in the members part

  1. Defend agents that read the web or email
  2. Keep an audit trail
  3. Recipes
  4. Patterns that work
  5. Mistakes to avoid
  6. Exercises

Sources

Checked against these on 13 Oct 2026.

  1. Claude Code: configure permissions (opens in a new tab)code.claude.com
  2. Claude Code: choose a permission mode (opens in a new tab)code.claude.com
  3. Claude Code: configure auto mode (opens in a new tab)code.claude.com
  4. Claude Code: configure the sandboxed Bash tool (opens in a new tab)code.claude.com
  5. Claude Code: choose a sandbox environment (opens in a new tab)code.claude.com
  6. Claude Code: security (opens in a new tab)code.claude.com
  7. Claude Code: settings files and precedence (opens in a new tab)code.claude.com
  8. Claude Code: deploy managed settings (opens in a new tab)code.claude.com
  9. Claude Code: all settings reference (opens in a new tab)code.claude.com
  10. Claude Code: hooks reference (opens in a new tab)code.claude.com
  11. Claude Code: monitoring and audit events (opens in a new tab)code.claude.com
  12. Claude Code: CLI reference (opens in a new tab)code.claude.com
  13. Claude Code: development containers (opens in a new tab)code.claude.com
  14. Claude Agent SDK: securely deploying AI agents (opens in a new tab)code.claude.com
  15. Codex: agent approvals and security (opens in a new tab)learn.chatgpt.com
  16. MCP security best practices (opens in a new tab)modelcontextprotocol.io