Is Claude Code safe? Mostly, if you keep its guard rails on. It’s an agent that reads your files and runs shell commands as your user, so the real risks come from what you let it do and what it reads: untrusted repos, web pages and plugins. Anthropic builds in permission prompts, deny rules and sandboxing. This guide covers what can actually go wrong and the settings that lock it down.
What Claude Code can do on your machine
Claude Code runs locally in your terminal (or IDE) with your user account’s access. By default it can:
- Read files in the folder you started it in, and its subfolders, without asking.
- Run a built-in set of read-only commands such as
ls,catandgit statuswithout asking. - Edit files, run other shell commands and fetch web pages, after you approve them (in Manual mode).
- Call any MCP servers, skills and plugins you’ve installed.
The working-directory boundary is a permission prompt, not a jail. Once you approve a Bash command, that command can touch anything your account can. That’s the key thing to understand about the risk.
The real risks
- Destructive commands. A wrong
rm -rf, agit push --forceor a database migration against the wrong environment. Usually a mistake rather than malice, and usually because someone approved it without reading. - Prompt injection. Instructions hidden in a README, a code comment, an issue or a web page that try to get the agent to do something you didn’t ask for, such as sending data somewhere with
curl. - Secrets exposure.
.envfiles, cloud credentials and SSH keys are just files. If Claude reads them they enter the conversation context. - Supply chain. MCP servers, skills and plugins run code or inject instructions. Anthropic reviews connectors against listing criteria for its directory, but says it does not security-audit MCP servers. A random GitHub plugin gets no review at all.
- Running with everything switched off.
--dangerously-skip-permissions(bypassPermissions mode) removes the prompts entirely and, in Anthropic’s words, offers no protection against prompt injection.
1. Pick the right permission mode
Press Shift+Tab to cycle modes, or start with claude --permission-mode plan. In short: default (Manual) asks before edits and commands, acceptEdits auto-approves file edits in the working directory, plan blocks edits until you approve a plan, and auto uses a classifier to review actions instead of you. Keep bypassPermissions for throwaway containers or VMs with no internet. I go through each one in Claude Code permission modes: plan mode and allow rules.
2. Write deny rules for secrets and risky commands
Deny rules apply in every mode, including bypassPermissions. Put them in .claude/settings.json for the project, or ~/.claude/settings.json for everything:
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Read(~/.ssh/**)",
"Bash(curl *)",
"Bash(git push *)"
]
}
}
Know the limits: Read deny rules cover Claude’s file tools and commands Claude Code recognises, such as cat and head, but not a Python script that opens the file itself. Bash rules match the command text, so they’re a speed bump, not a wall. Check what’s in effect with /permissions.
3. Turn on the sandbox
For enforcement that doesn’t depend on command text, run /sandbox. It isolates Bash commands at the operating-system level, restricting which paths they can write and which network hosts they can reach. Because the boundary is enforced by the OS, sandboxed commands can run with fewer prompts and a prompt-injected curl to an unknown host simply fails.
4. Add hooks as a safety net
A PreToolUse hook runs before every tool call and can block it. It’s a good place for a hard stop on things like rm -rf /, force pushes or DROP TABLE. There’s a working script in Claude Code hooks: block dangerous commands before they run.
5. Isolate untrusted work
- Run Claude Code inside a dev container or VM, so its commands hit the container rather than your host. Anthropic’s reference devcontainer adds an egress firewall. It still can’t stop a malicious project stealing what’s inside the container, so don’t mount
~/.sshor cloud credentials into it. - Read the workspace trust dialog properly. Trusting a folder lets its project settings, hooks and
.mcp.jsonservers come into play, andclaude -pskips that prompt entirely. - Don’t pipe untrusted content straight into Claude, and don’t start it in your home directory.
6. Vet skills, plugins and MCP servers
Install from authors you trust, read the code first, and run an audit tool over it. Prism Scanner checks skills and plugins for risky patterns before you install them. Remember that a project’s .mcp.json doesn’t show every server a session can load: user-scope servers, claude.ai connectors and plugins can add more. List them with /mcp and disable what you don’t use.
7. Review every diff
Anthropic is explicit that you’re responsible for reviewing proposed code and commands before approving them. Read the diff, commit often so git can undo mistakes, use /rewind to roll back to a checkpoint, and run /security-review over a branch before you merge.
So, is it safe?
Used with the default prompts, sensible deny rules and the sandbox, Claude Code is about as safe as any tool that can run commands on your machine, and safer than pasting scripts from a chat window. The danger comes from turning everything off, approving prompts without reading them, and installing extensions you haven’t looked at.

Leave a Reply
You must be logged in to post a comment.