Skip to content
Academy ofAI Learning

~/academy $ claude learn security-for-claude-code

Security for Claude Code

What Claude Code can access on your machine, permission rules that hold, the sandbox, keeping secrets safe, prompt injection, and checking what you approve. 9 min

Step 1 of 7

$ Read

What Claude Code can reach

Claude Code runs as you. It reads files in the folder you started it in without asking, and in Manual mode it asks before editing files or running most commands. A short list of read-only commands, such as ls and git status, runs without a prompt.

The folder boundary is a permission prompt, not a wall. A shell command you approve can write anywhere your user account can. Hooks, MCP servers and plugins also run with your full permissions.

Permission rules are enforced by Claude Code, not by the model. A line in CLAUDE.md saying never touch production changes what Claude tries, not what it is allowed to do. Real limits come from rules, modes, hooks and the sandbox.

Lesson notes: Security for Claude Code

Everything in this lesson as text, for revision or to read without the interactive steps. By the end you will be able to: You lock down a project so secrets cannot be read, commands are sandboxed and untrusted content cannot quietly take control.

  1. Step 1 of 7 · Read

    What Claude Code can reach

    Claude Code runs as you. It reads files in the folder you started it in without asking, and in Manual mode it asks before editing files or running most commands. A short list of read-only commands, such as ls and git status, runs without a prompt.

    The folder boundary is a permission prompt, not a wall. A shell command you approve can write anywhere your user account can. Hooks, MCP servers and plugins also run with your full permissions.

    Permission rules are enforced by Claude Code, not by the model. A line in CLAUDE.md saying never touch production changes what Claude tries, not what it is allowed to do. Real limits come from rules, modes, hooks and the sandbox.

  2. Step 2 of 7 · Read

    Rules that hold

    Rules are checked in a fixed order: deny, then ask, then allow. The first match decides. A deny in any settings file beats an allow in any other, so a broad deny cannot be undone by a narrower allow.

    Bash rules match the command text Claude writes. Bash(curl *) stops curl https://example.com but not /usr/bin/curl or sh -c 'curl ...'. Treat Bash rules as a guard on normal use, and use the sandbox for limits that do not depend on wording.

    Run /permissions regularly to see every rule and which file it came from.

    .claude/settings.json
    {
      "permissions": {
        "deny": [
          "Read(./.env)",
          "Read(./.env.*)",
          "Read(./secrets/**)",
          "Bash(curl *)"
        ],
        "ask": ["Bash(git push *)"]
      }
    }
  3. Step 3 of 7 · Read

    The sandbox

    The sandbox is a boundary the operating system enforces around the shell commands Claude runs. Turn it on with /sandbox or "sandbox": { "enabled": true } in settings. It runs on macOS, Linux and WSL2; on native Windows commands run unsandboxed (checked 18 November 2026). On Linux and WSL2, install bubblewrap and socat first.

    By default sandboxed commands can write only to the working folder, a temp folder and folders you add. Network traffic goes through a proxy that checks each host against the domains you allow, a list that starts empty. A host outside it prompts you in Manual mode and is refused in auto and dontAsk modes (checked 18 November 2026).

    Two gaps to know. Reads are still allowed across most of the machine, including ~/.ssh, so keep your Read deny rules. And the sandbox covers shell commands only: Claude's file tools, MCP servers and hooks run outside it.

  4. Step 4 of 7 · Read

    Secrets and prompt injection

    Secrets: deny reads of .env and secrets folders, keep keys in environment variables, and reference them as ${VAR} in .mcp.json rather than writing them in. Claude Code stores its own credentials in the macOS Keychain where available, and in a file only your user can read on Linux.

    Prompt injection is text in a web page, issue, document or tool result written to give Claude new instructions, such as asking it to send a file somewhere. Claude Code helps: curl and wget are not auto-approved, and for most pages WebFetch passes Claude the answer from a separate model call instead of the raw page.

    Your habits matter more. Read commands before you approve them, do not pipe untrusted content straight into Claude, check changes to critical files, and use a virtual machine or dev container for risky work.

  5. Step 5 of 7 · Read

    Repositories you did not write

    In an interactive session, a new folder shows a workspace trust dialog first. Before accepting, look at .claude/settings.json (hooks and allow rules), .mcp.json (servers) and .claude/agents.

    claude -p shows no trust dialog, so a repository's hooks and .mcp.json servers can run. For code you have not reviewed, use --bare, or --setting-sources user, or --settings '{"disableAllHooks": true}'.

    Before you push, /security-review checks the changes on your branch for problems such as injection and data exposure. If you find a vulnerability in Claude Code itself, report it privately through Anthropic's HackerOne programme.

  6. Step 6 of 7 · Sort

    Enforced or just a request?

    Does Claude Code enforce each of these, or does it only shape what Claude tries?

    • Read(./.env) in permissions.deny
    • "Never read the .env file" in CLAUDE.md
    • A PreToolUse hook that exits with code 2
    • Asking Claude to be careful with production
    • Sandbox network access limited to registry.npmjs.org
    • A skill description saying "read-only"
    Show the answers
    • Read(./.env) in permissions.deny: Enforced by Claude Code. Claude Code refuses matching reads whatever the prompt says.
    • "Never read the .env file" in CLAUDE.md: Only a request. An instruction the model usually follows, not a rule Claude Code checks.
    • A PreToolUse hook that exits with code 2: Enforced by Claude Code. The tool call is blocked before it runs.
    • Asking Claude to be careful with production: Only a request. Helpful context, but nothing stops a risky command except rules and prompts.
    • Sandbox network access limited to registry.npmjs.org: Enforced by Claude Code. Sandboxed commands reach the network only through the proxy, which checks every host against your list.
    • A skill description saying "read-only": Only a request. Descriptions guide when a skill is used. Tool limits need rules or a subagent tools list.
  7. Step 7 of 7 · Quiz

    Check your understanding

    You turned on the sandbox. Which risk is still open unless you add something else?

    • A sandboxed command writing outside the project folder
    • A sandboxed command calling an unknown website
    • Claude reading ~/.ssh or a .env file
    Show the answer

    Claude reading ~/.ssh or a .env file The sandbox allows reads across most of the machine by default. Add Read deny rules for secrets.