# Permission Rules and Sandbox

> 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:** [Claude Code Basics](https://learn.benibix.com/learn/ai-claude-code)  
**Time:** 11 min

**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

## 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.

```json
{
  "permissions": {
    "allow": ["Bash(npm test)", "Bash(npm run lint)"],
    "deny": ["Read(./.env)", "Bash(git push *)"]
  }
}
```
Two commands run without asking. The secrets file can never be read, and nothing can be pushed.

![A tool call meets three gates in a row: deny, ask, allow. A deny match is blocked, an ask match asks you, an allow match runs, and a call that matches none is left to the mode. A note says a deny rule always wins.](https://learn.benibix.com/diagrams/cc-permission-rule.svg)

### 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.

**Words in this lesson:** [Permission Rule](https://learn.benibix.com/term/ai/permission-rule), [Claude Code Sandbox](https://learn.benibix.com/term/ai/claude-code-sandbox), [Project Trust](https://learn.benibix.com/term/ai/project-trust), [Protected Paths](https://learn.benibix.com/term/ai/protected-paths)

**Question:** You allow Bash(git status) and deny Bash(git *). What happens when Claude runs git status?

**Answer:** It is denied, because deny is checked first. Rules are checked deny, then ask, then allow, and how exact a rule is does not change that. The deny matches first, so the command is blocked.

---

Source: https://learn.benibix.com/learn/ai-claude-code/permission-rules-and-sandbox
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
