Get the free coreGet core

How to run Claude Code safely: a 10-step setup for your Mac

Updated 6 min readSection 03 / Is it safe?
SHORT ANSWER

To run Claude Code safely on a Mac, stack small controls instead of trusting one. Keep it updated, start in a project folder, pick the permission mode on purpose, add deny rules for secrets, turn on the sandbox and add a blocking hook. Keep keys out of reach and commit to Git before long runs. The sandbox is off by default, and the bypass flag belongs only in isolated environments.

01Is it safe to run Claude Code on your computer?

Not without layers. Since v2.1.283, new terminal sessions start in auto mode, where a classifier model reviews each action. In manual mode Claude Code starts with read-only permissions and asks before it edits files, runs tests or executes commands. The catch is that the working directory boundary is a permission prompt, so a Bash command you approve can still write anywhere your user account can. Safety then depends on how carefully you read what you approve.

Real cases show what is at stake. One GitHub issue reports that Claude Code ran a destructive recursive delete and removed all user files in the home directory. Advisories have also been published for approval bypasses, and fixes reach standard auto-update users automatically. The full advisory list is on the Claude Code security page. The aim of the steps below is to run Claude Code safely even when one prompt gets approved by mistake.

02Steps 1 to 3: update, folder and mode

Here is how to run Claude Code safely. It starts before the first prompt, with three choices.

Step one, update. Native installations update in the background to keep you on the latest version. After installing, open a new terminal and run claude --version; a working installation prints a version number.

claude --version

Step two, the folder. In an interactive session, Claude Code shows the workspace trust dialog, a "do you trust this folder" prompt, when you start it in a folder you have not trusted. Read it. Start Claude Code from a project subdirectory, where trust acceptance is saved per directory.

A cloned repository cannot grant itself bypass mode. Current docs say that bypassPermissions set in the project .claude/settings.json or settings.local.json does not take effect, and the session starts in Manual mode. An older advisory described a malicious repository using that setting to skip the trust dialog, so update first.

Step three, the mode. Press Shift+Tab at any time to switch the permission mode of your session. The choice matters because the starting mode is not the strictest one.

ModeWhat it doesWhere it fits
Manual (config value default)Asks before Bash commands except a built-in set of read-only onesSensitive work on your own Mac
AutoA separate classifier model reviews actions; it reduces prompts but does not guarantee safetyEveryday work, where it is the starting mode since v2.1.283
bypassPermissionsThe --dangerously-skip-permissions flag is equivalentOnly containers, VMs or dev containers without internet access

What auto mode blocks and allows is listed on the auto mode page, and all mode names are on the permissions page.

03Steps 4 and 5: deny rules and the sandbox

Step four, deny rules. A deny rule names something Claude must not touch. Read(./.env) matches reading the .env file in the current directory. Deny rules block in every mode, including bypassPermissions. For blocking edits, add an Edit deny rule per path under permissions.deny in .claude/settings.json, such as Edit(/.env).

Rules live in a permissions block. The docs' example lets npm scripts and git commits run without asking and refuses commands that begin with git push:

{
  "permissions": {
    "allow": [
      "Bash(npm run *)",
      "Bash(git commit *)"
    ],
    "deny": [
      "Bash(git push *)"
    ]
  }
}

Add your own lines to the deny list, for example "Read(./.env)" and "Edit(/.env)".

Treat a deny rule as a strong guard against honest mistakes, not a wall. It does not match the same program by path or inside sh -c, and a rule on WebFetch alone does not prevent network access if Bash is allowed. Rule syntax and precedence are on the permissions page.

Step five, the sandbox. A sandbox is a fence the operating system enforces around shell commands. Turn it on with /sandbox in a session, or set sandbox.enabled to true in a settings file such as ~/.claude/settings.json. On macOS it uses the built-in Seatbelt framework. Because the operating system enforces it, the boundary holds regardless of what the model chose to run. To check it, run touch ~/sandbox-probe; it should fail with "Operation not permitted" on macOS.

Know its limits:

More in Claude Code sandbox.

04Step 6: a hook that blocks

A hook is your own script that Claude Code runs at a set point. A PreToolUse hook that returns deny blocks the tool even in bypassPermissions mode. The working scripts, the settings JSON and the exit-code rules are all on the Claude Code hooks page.

05Steps 7 and 8: untrusted inputs and secrets

Step seven, MCP servers and repositories. An MCP server is a helper program that gives Claude extra tools. Verify that you trust each server before connecting it, because servers that fetch external content can expose you to prompt injection. Prompt injection is a technique where an attacker inserts malicious text to override the assistant's instructions. A cloned repository cannot approve its own servers, but reviewing .mcp.json does not show every server a session can load. A sandbox escape advisory needed exactly that setup: a malicious cloned repository with prompt injection content.

Step eight, secrets. Keep keys where Claude cannot reach them. In a container, avoid mounting ~/.ssh or cloud credential files, and prefer repository-scoped or short-lived tokens. Two facts about your own machine are worth knowing. Session transcripts are stored locally in plaintext under ~/.claude/projects/ for 30 days by default, so a secret you paste into a prompt lands there. And sandboxed processes inherit Claude Code's environment, including any secrets in it.

06Step 9: a way back

Commit before a long run. Claude Code tracks edits made by its file editing tools, and /rewind or /undo opens the rewind menu. It keeps file snapshots for the 100 most recent checkpoints in a session. A file that only Bash commands changed is not tracked, so use Git to revert it. Manual changes you make outside Claude Code are normally not captured either.

07Step 10: the flag stays in a container

--dangerously-skip-permissions is the same as --permission-mode bypassPermissions. If you need it for a long unattended job, move the job into a container, VM or dev container without internet access. The walkthrough is on the devcontainer page, and the flag itself is covered in dangerously skip permissions.

08How good is Claude Code security by itself?

It gives you a base to build on. Rules are enforced by Claude Code, while instructions in a prompt only shape what Claude tries to do. The sandbox is enforced by the operating system. But the sandbox is off by default, and one approved command can reach as far as your user account can. That is why Claude Code security best practices come down to layers and not to a single switch. The broader review is in is Claude Code safe.

09The short version

To run Claude Code safely, update it, start in a trusted project folder and pick a mode on purpose. Deny reads of secrets, turn on the sandbox and add a blocking hook. Treat MCP servers and cloned repos as untrusted, commit before you let it work, and keep the bypass flag for containers. The wider picture of what an agent may do on its own is in AI agent permissions.

Even a careful setup misses things, so it helps to know what actually ran. Artificial Immunity's free, open-source core watches Claude Code, MCP servers and every program start on your Mac, and reports what it finds without blocking anything.

FAQ

Is it safe to run Claude Code on your computer?

It carries real risk unless you add layers. New sessions start in auto mode since v2.1.283; in manual mode Claude Code starts with read-only permissions and asks before edits, tests and commands, but an approved Bash command can write anywhere your user account can. Interactive sessions start in auto mode since v2.1.283.

How to make Claude Code secure?

Layer the controls: a chosen permission mode, deny rules for secrets, the sandbox, a blocking PreToolUse hook and Git for recovery. Each one covers a gap in the others.

What is the safest way to use Claude Code?

Use manual mode with the sandbox on, in a project folder you trust. For unattended work use a container, because the docs say the bypass mode is for isolated environments like containers, VMs or dev containers without internet access.

What are the risks of Claude Code?

Prompt injection, meaning malicious text that overrides the assistant's instructions, untrusted MCP servers, cloned repositories and approvals given without reading.

How good is Claude Code security?

It gives you a base: rules enforced by Claude Code, not by the model, and a sandbox enforced by the operating system. But the sandbox is off by default and sandboxing is not a complete isolation boundary.

Does Claude Code send my code anywhere?

Claude Code runs locally, and to talk to the model it sends data over the network, including all user prompts and model outputs, encrypted in transit via TLS 1.2+.

Sources

  1. Claude Code docs: security
  2. Claude Code docs: permissions
  3. Claude Code docs: permission modes
  4. Claude Code docs: sandboxing
  5. Claude Code docs: hooks guide
  6. Claude Code docs: MCP
  7. Claude Code docs: quickstart
  8. Claude Code docs: checkpointing
  9. Claude Code docs: data usage
  10. Claude Code security advisories
  11. Claude Code issue #10077
  12. Artificial Immunity
Set up Claude Code the careful way? Artificial Immunity watches the Mac where your agents work.Get the free core