Claude Code guide in three levels, Beginner to Advanced: hands-on lessons with checked exercises, every volatile fact cited to its source. Independent community guide.
JavaScript agent-skillsagentic-codingai-agentsanthropicanthropic-claudebest-practicesclaudeclaude-aiclaude-codeclaude-code-guideclaude-code-hooksclaude-code-pluginsclaude-code-skillsclaude-code-tutorialclaude-code-workflowsguidelearn-claude-codemcpsubagentstutorial
docs: add the Intermediate lesson on permissions, settings scopes and the sandbox (#84)
Wesam Abousaidfb1253a76f54
diff --git a/README.md b/README.mdindex 63fec3c..5016812 100644--- a/README.md+++ b/README.md@@ -46,7 +46,7 @@ macOS, Linux and WSL. For Windows and other installers, see the [official setup**Beginner Electives:** [IDE extensions](docs/beginner/electives/ide-extensions.md) · [Screenshots and images](docs/beginner/electives/screenshots-and-images.md) · [The built-in teachers](docs/beginner/electives/built-in-teachers.md)-**Intermediate** (being rebuilt): [Level index](docs/intermediate/README.md) · [Turn a repeated workflow into a skill](docs/intermediate/01-first-skill.md) · [Organize project memory and see what loaded](docs/intermediate/02-organize-memory.md) · [Pick the model and effort](docs/intermediate/03-model-and-effort.md)+**Intermediate** (being rebuilt): [Level index](docs/intermediate/README.md) · [Turn a repeated workflow into a skill](docs/intermediate/01-first-skill.md) · [Organize project memory and see what loaded](docs/intermediate/02-organize-memory.md) · [Pick the model and effort](docs/intermediate/03-model-and-effort.md) · [Permissions, settings scopes and the sandbox](docs/intermediate/04-permissions-and-sandbox.md)**Advanced** (being rebuilt): [Level index](docs/advanced/README.md)diff --git a/docs/intermediate/03-model-and-effort.md b/docs/intermediate/03-model-and-effort.mdindex 98d4c39..7cda99e 100644--- a/docs/intermediate/03-model-and-effort.md+++ b/docs/intermediate/03-model-and-effort.md@@ -106,4 +106,4 @@ If the skill check says the model is larger than the task needs, set `model: son<sub>Sources: [Model configuration](https://code.claude.com/docs/en/model-config) · [Commands](https://code.claude.com/docs/en/commands) · [Choosing a Claude model and effort level in Claude Code](https://claude.com/blog/claude-model-and-effort-level-in-claude-code) · [Extend Claude with skills](https://code.claude.com/docs/en/skills) · [Choose a permission mode](https://code.claude.com/docs/en/permission-modes) · [How Claude Code uses prompt caching](https://code.claude.com/docs/en/prompt-caching)</sub>-<sub>← [Organize project memory and see what loaded](02-organize-memory.md) · [Intermediate index](README.md) · Topic: [Models, effort and cost](../topics/models-effort-and-cost.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=i-3)</sub>+<sub>← [Organize project memory and see what loaded](02-organize-memory.md) · [Intermediate index](README.md) · [Permissions, settings scopes and the sandbox](04-permissions-and-sandbox.md) → · Topic: [Models, effort and cost](../topics/models-effort-and-cost.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=i-3)</sub>diff --git a/docs/intermediate/04-permissions-and-sandbox.md b/docs/intermediate/04-permissions-and-sandbox.mdnew file mode 100644index 0000000..8e69d69--- /dev/null+++ b/docs/intermediate/04-permissions-and-sandbox.md@@ -0,0 +1,104 @@+# Permissions, settings scopes and the sandbox++<sub>**Intermediate** · Lesson 4 of 8 · about 20 minutes · Needs: [Organize project memory and see what loaded](02-organize-memory.md) · Verified against Claude Code v2.1.285 (stable) on 2026-10-06</sub>++## Goal++By the end of this lesson you can put a permission rule in the settings file whose scope fits it, see which rules are in force, and turn on the sandbox so the shell commands Claude runs can't write outside your project, a temporary folder and any folders you've added.++## You need++- Your copy of the practice template, for the Worked example, with Node.js LTS: the check runs from it. One of your own repositories with a test command, for Your turn; or use the template copy for both.+- macOS, Linux or WSL 2. On Linux and WSL 2, the sandbox needs `bubblewrap` and `socat` ([Set up Linux and WSL2](https://code.claude.com/docs/en/sandboxing#set-up-linux-and-wsl2)); a Codespace on your template copy has both.+- Usage: light.++## The idea++Claude Code reads settings from four files, and the file a rule goes in decides who it affects ([Settings](https://code.claude.com/docs/en/settings#settings-files-and-who-they-affect)):++| File | Affects | Put here |+|---|---|---|+| `~/.claude/settings.json` | You, in every project | Your own preferences |+| `.claude/settings.json`, committed | Everyone in the project | Team rules: files Claude must never read, commands everyone runs |+| `.claude/settings.local.json`, kept out of git | You, in this project | Your own exceptions. "Yes, and don't ask again" on a Bash command saves here |+| Managed settings | Everyone your organization deploys them to | Policy your settings can't override, apart from a few security keys where the stricter value wins |++When the same key is set in more than one place, the higher level wins: managed, then the command line, then local, then shared project, then user ([Settings precedence](https://code.claude.com/docs/en/settings#settings-precedence)). Rule lists such as `permissions.allow` merge across the files instead. Among the rules, deny is checked first, then ask, then allow, and the first match decides ([Configure permissions](https://code.claude.com/docs/en/permissions#manage-permissions)).++Permission rules govern Claude's tools. The [sandbox](https://code.claude.com/docs/en/sandboxing) adds a boundary that the operating system enforces around the shell commands Claude runs: by default they can write only in the project, a per-user temporary folder and any folders you've added with `--add-dir` or `/add-dir`, and reach the network only through a proxy that checks each host against the hosts you allow. It's off until you turn it on. In its auto-allow mode, a command that runs inside it needs no permission prompt.++## Worked example++In your practice copy:++1. Start `claude` and run `/status`. Its `Setting sources` line lists the settings files this session loaded.+2. Save the team's rules as `.claude/settings.json`. These are the docs' rules for keeping Claude out of `.env` files ([Exclude sensitive files](https://code.claude.com/docs/en/settings-reference#exclude-sensitive-files)), plus the test command:++ ```json+ {+ "permissions": {+ "allow": ["Bash(npm test)"],+ "deny": ["Read(./.env)", "Read(./.env.*)"]+ }+ }+ ```++ Claude Code reloads a settings file when it changes ([When edits take effect](https://code.claude.com/docs/en/settings#when-edits-take-effect)). Run `/permissions`: it lists `Bash(npm test)` among the allow rules and the two `Read` rules among the deny rules.+3. Ask Claude to `Run npm test`. It runs without a permission prompt: the allow rule covers it.+4. Turn on the sandbox. Run `/sandbox` and, on the Mode tab, select auto-allow. Claude Code saves the setting to `.claude/settings.local.json`, your personal file ([Get started](https://code.claude.com/docs/en/sandboxing#get-started)).+5. Ask Claude to try a write outside the project:++ ```text+ Run this exact command and show me its output: touch ~/sandbox-probe+ ```++ It runs without a prompt and fails: `Operation not permitted` on macOS, `Read-only file system` on Linux and WSL 2 ([Confirm commands run inside the sandbox](https://code.claude.com/docs/en/sandboxing#confirm-commands-run-inside-the-sandbox)). If Claude offers to retry outside the sandbox, decline.++## Your turn++Set up the same split in your own repository.++1. Save this partial file as `.claude/settings.json`, and replace each `TODO` with a rule. Allow only the one command that runs your tests, such as `Bash(npm test)` or `Bash(pytest)`:++ ```json+ {+ "permissions": {+ "allow": ["TODO: the command that runs your tests"],+ "deny": ["TODO: reading .env", "TODO: reading .env.local and the other .env.* files"]+ }+ }+ ```++2. Commit it: these are rules for everyone who works in the repository.+3. In a session there, turn on the sandbox with `/sandbox` in auto-allow mode, and repeat the Worked example's step 5.+4. Run `git status`. `.claude/settings.local.json` isn't listed: Claude Code keeps it out of git when it creates it ([Keep personal settings out of a repository](https://code.claude.com/docs/en/settings#keep-personal-settings-out-of-a-repository)).++## Check++You are done when all of these are true:++- [ ] The committed `.claude/settings.json` denies reading `.env` and `.env.*` files and allows one test command: `git show HEAD:.claude/settings.json | jq .permissions` shows them.+- [ ] The sandbox is on, and your personal file stays out of git: `jq .sandbox .claude/settings.local.json` shows `"enabled": true`, and `git ls-files .claude/settings.local.json` prints nothing.+- [ ] Self-check (not tested): Claude's `touch ~/sandbox-probe` failed without asking you first.++Run `npm run check -- i-4 --dir <your repo>` from your practice copy, or `npm run check -- i-4` in the copy itself.++If the first item fails on a broad rule, replace it with the one command: `Bash(npm *)` would let Claude run any npm command without asking. If `/sandbox` shows only a Dependencies tab, install `bubblewrap` and `socat`, restart Claude Code and run `/sandbox` again.++## Watch out++- The sandbox wraps shell commands only. Claude's file and web tools run outside it and follow your permission rules; hooks and local MCP servers run outside it with your full access ([What runs outside the sandbox](https://code.claude.com/docs/en/sandboxing#what-runs-outside-the-sandbox)). If the sandbox can't start, Claude Code runs commands unsandboxed unless `sandbox.failIfUnavailable` is `true`.+- On its own, a `Read` deny rule covers Claude's file tools and the file commands Claude Code recognizes in Bash, such as `cat`, but not a script that opens files itself ([Read and Edit](https://code.claude.com/docs/en/permissions#read-and-edit)). With the sandbox on, Claude Code also adds your `Read` deny paths to the sandbox's [`filesystem.denyRead`](https://code.claude.com/docs/en/settings-reference#sandbox-filesystem-denyread), so sandboxed commands and the processes they start can't read those files either.+- In a Codespace or another container, if sandboxed commands fail with `Can't mount proc on /newroot/proc`, see [Bubblewrap fails to start inside a container](https://code.claude.com/docs/en/sandboxing#bubblewrap-fails-to-start-inside-a-container).++## Go further++- [How we built Claude Code auto mode](https://www.anthropic.com/engineering/claude-code-auto-mode): Anthropic on what auto mode's classifier catches and what it misses.+- [Making Claude Code more secure and autonomous with sandboxing](https://www.anthropic.com/engineering/claude-code-sandboxing): why the sandbox has a filesystem boundary and a network boundary.+- [Security](https://code.claude.com/docs/en/security): how Claude Code's protections fit together.++---++<sub>Sources: [Settings files and precedence](https://code.claude.com/docs/en/settings) · [All settings](https://code.claude.com/docs/en/settings-reference) · [Configure permissions](https://code.claude.com/docs/en/permissions) · [Configure the sandboxed Bash tool](https://code.claude.com/docs/en/sandboxing)</sub>++<sub>← [Pick the model and effort](03-model-and-effort.md) · [Intermediate index](README.md) · Topic: [Permissions and safety](../topics/permissions-and-safety.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=i-4)</sub>diff --git a/docs/intermediate/README.md b/docs/intermediate/README.mdindex 70012b3..a40821e 100644--- a/docs/intermediate/README.md+++ b/docs/intermediate/README.md@@ -41,7 +41,7 @@ They combine: a [plugin](https://code.claude.com/docs/en/plugins) packages skill1. [Turn a repeated workflow into a skill](01-first-skill.md)2. [Organize project memory and see what loaded](02-organize-memory.md)3. [Pick the model and effort](03-model-and-effort.md)-4. Permissions, settings scopes and the sandbox+4. [Permissions, settings scopes and the sandbox](04-permissions-and-sandbox.md)5. Enforce a rule with a hook6. Delegate to a custom subagent7. Connect a tool with MCPdiff --git a/docs/reference/commands.md b/docs/reference/commands.mdindex 36d8855..d90acea 100644--- a/docs/reference/commands.md+++ b/docs/reference/commands.md@@ -28,8 +28,8 @@ Electives: `/powerup` and `/output-style` ([the built-in teachers](../beginner/e- `/doctor`: check your setup; `/doctor prompt-audit` checks your instruction files. [Organize project memory and see what loaded](../intermediate/02-organize-memory.md)- `/model`: switch the model and save it as your default; for models that support it, the left and right arrow keys adjust effort. [Pick the model and effort](../intermediate/03-model-and-effort.md)- `/effort`: set the effort level. [Pick the model and effort](../intermediate/03-model-and-effort.md)-- `/permissions`: manage allow, ask and deny rules. *Permissions, settings scopes and the sandbox*-- `/sandbox`: turn the sandbox on or off. *Permissions, settings scopes and the sandbox*+- `/permissions`: manage allow, ask and deny rules. [Permissions, settings scopes and the sandbox](../intermediate/04-permissions-and-sandbox.md)+- `/sandbox`: turn the sandbox on or off. [Permissions, settings scopes and the sandbox](../intermediate/04-permissions-and-sandbox.md)- `/hooks`: see which hooks are configured. *Enforce a rule with a hook*- `/agents`: a reminder of how to create and manage subagents. *Delegate to a custom subagent*- `/mcp`: manage MCP server connections and sign-ins. *Connect a tool with MCP*diff --git a/docs/reference/feature-map.md b/docs/reference/feature-map.mdindex a4a8112..2d4fb4c 100644--- a/docs/reference/feature-map.md+++ b/docs/reference/feature-map.md@@ -36,7 +36,7 @@ How to read it:| [Auto mode](https://code.claude.com/docs/en/permission-modes); taught in [Permission modes and plan mode](../beginner/02-permission-modes-and-plan-mode.md) | – | A Claude subscription, the Console and Claude Platform on AWS; on Bedrock, Agent Platform and Foundry with newer models only. Team and Enterprise admins can turn it off || [Checkpointing and rewind](https://code.claude.com/docs/en/checkpointing); taught in [Keep a session on track](../beginner/04-keep-a-session-on-track.md) | – | Every provider || [CLAUDE.md memory](https://code.claude.com/docs/en/memory); taught in [Project memory with CLAUDE.md](../beginner/05-project-memory.md) and [Organize project memory and see what loaded](../intermediate/02-organize-memory.md) | – | Every provider |-| [Sandbox](https://code.claude.com/docs/en/sandboxing) | – | Every provider |+| [Sandbox](https://code.claude.com/docs/en/sandboxing); taught in [Permissions, settings scopes and the sandbox](../intermediate/04-permissions-and-sandbox.md) | – | Every provider || [Output styles](https://code.claude.com/docs/en/output-styles); taught in [the built-in teachers](../beginner/electives/built-in-teachers.md) | – | Every provider || [Status line](https://code.claude.com/docs/en/statusline) | – | Every provider || [`/goal`](https://code.claude.com/docs/en/goal) | – | Every provider |diff --git a/docs/topics/permissions-and-safety.md b/docs/topics/permissions-and-safety.mdindex 152392a..feb2197 100644--- a/docs/topics/permissions-and-safety.md+++ b/docs/topics/permissions-and-safety.md@@ -8,6 +8,7 @@ What Claude Code may do without asking, and how to keep it away from what it sho- Beginner: [Permission modes and plan mode](../beginner/02-permission-modes-and-plan-mode.md)- Beginner: [Your first change, from request to commit](../beginner/03-first-change.md)+- Intermediate: [Permissions, settings scopes and the sandbox](../intermediate/04-permissions-and-sandbox.md)Later lessons on this topic are linked here in level order, with its Electives, as they are published.