Permission Rules and Sandbox
Level 2 · Asking before it acts
How Claude Code permission rules allow, ask about or deny a tool. Why deny always wins, what the sandbox fences in, and which paths stay protected.
Course contentsLesson 6 of 16
Level 1 · Starting out
Level 2 · Asking before it acts
Level 3 · Telling it how you work
Level 4 · The tools it uses
Level 5 · Growing past one chat
After this lesson you can
- Write an allow rule and a deny rule
- Say the order rules are checked in
- Explain what the sandbox and project trust each guard
11 mincovers 4 glossary entries
Worth reading first: Claude Code Permission Modes
How rules decide what Claude may do
A permission rule tells Claude Code to allow a tool, ask about it, or deny it. A rule names a tool and can add a pattern in brackets, such as Bash(npm test) or Read(./.env). Rules are checked in a fixed order: deny first, then ask, then allow. The first rule that matches decides.
So a deny always wins. If you deny Bash(aws *), then an allow for Bash(aws s3 ls) does nothing, even though it is more exact. A deny rule also holds in every mode, even bypass. That makes deny the right tool for anything that must never happen.
Rules live in a settings file, in three lists named allow, ask and deny. A file in the project can be shared with the whole team through git. Run /permissions in a session to see each rule in force, and where each one came from.
When you answer a prompt with yes, and don't ask again, Claude Code writes a rule for you. For a shell command it lasts for that project and that command. For a file edit it lasts until the session ends. That is how most people build up their list without writing it by hand.
The sandbox is a second wall, set by your computer's own system. It fences the shell commands Claude runs, so they can only write to the folders and reach the sites you chose. Inside that wall, commands can run without asking, because they cannot reach anything else. It is off at first. Switch it on with /sandbox.
The first time you open a folder, Claude Code asks whether you trust it. Until you say yes, it holds back some things the project brings, such as its allow rules. A repo you cloned from a stranger could carry settings meant to let Claude do more than you want.
A few paths are protected in every mode, such as .git, .vscode, .idea and most of .claude. Writing to them gets an extra check. Manual and accept edits mode ask you, auto mode sends the write to its checker, and don't ask mode turns it down. An allow rule does not skip this check.
{
"permissions": {
"allow": ["Bash(npm test)", "Bash(npm run lint)"],
"deny": ["Read(./.env)", "Bash(git push *)"]
}
}Worked example
Lucy keeps her secrets file shut
Lucy's project keeps keys in a .env file. She adds a deny rule for Read(./.env) to the project settings, and an allow rule for her 2 test commands.
Later she switches to auto mode for a long task. Claude runs the tests 9 times without asking, and never opens the keys.
The words for this lesson4
Check yourself
You allow Bash(git status) and deny Bash(git *). What happens when Claude runs git status?
Finished this lesson?
Marking it complete also marks its 4 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.