Skip to content

Guide

Claude Code Security: Hardening AI Coding Agents on Developer Machines

By Lucas Weber, CyberSec42 · Updated 28 Oct 2026

CyberSec42

Claude Code security comes down to one decision: what the agent may do on your machine without asking. Claude Code and Cursor read files, change code and run shell commands with the privileges of your user account, and any text the agent reads can try to steer it somewhere else. You make them safe to use with the right approval mode, hard deny rules, a sandbox with a network allowlist, vetted MCP servers and a team policy that switches off the risky modes.

The short version.

What the agent can do

Files, shell, network.

Go to section

Modes and sandbox

Approvals, rules, isolation.

Go to section

Prompt injection

Via repos, issues, web pages.

Go to section

MCP and configuration

Servers, plugins, repo hooks.

Go to section

Secrets and supply chain

.env, tokens, packages.

Go to section

Team checklist

Policy and hardening.

Go to section

What a coding agent can do on your machine

A chat assistant suggests code; a coding agent ships it. It reads the repository, creates files, runs tests, installs packages and fetches web pages, all from a local process running as you. Whatever that process can reach, an instruction smuggled into the agent's context can potentially reach too. The fundamentals of AI agent security apply directly, except that the agent doesn't live on a server. It lives on a developer laptop next to SSH keys, cloud credentials and browser sessions.

This is how the vendors describe the default capabilities (documentation as of 28 October 2026):

CapabilityClaude Code (Manual mode)Cursor
Reading filesNo prompt inside the working directory and approved additional directories; prompts outside themNo prompt; per the docs, by default also outside the workspace
Editing filesPromptsWorkspace files without a prompt; configuration files only after approval
Shell commandsPrompts, except for a fixed set of read-only commands such as ls, cat, git statusGoverned by the selected run mode: allowlist, Auto-review with a classifier, or run everything
NetworkFetch tools and commands such as curl and wget promptTools only reach GitHub, direct links and web search; in the terminal, the sandbox governs access

Anthropic is explicit about one limitation: the working-directory boundary is a permission prompt, not isolation. A Bash command you approve can still write anywhere your user account can. Cursor adds that changes are written to disk immediately and, with auto-reload enabled, may execute before you have reviewed them.

Choosing approval modes and the sandbox

Claude Code permission modes

According to the permissions documentation, Claude Code has six modes. Which one a session starts in depends on how you launch it: recent versions start interactive terminal and VS Code sessions in auto when it is available, while claude -p and the Agent SDK start in default. Check the actual mode with /permissions instead of assuming it.

ModeBehaviourWhen to use it
default (Manual)Asks on first use of each toolThird-party repositories, sensitive projects
planReads and explores, doesn't edit source filesAnalysis before a change
acceptEditsAccepts file edits and basic filesystem commands in the working directoryYour own project, with changes tracked in Git
autoA separate classifier model reviews actions instead of youTasks with a clear direction; per Anthropic, not a safety guarantee
dontAskDenies anything that would otherwise promptAutomated runs with a fixed allowlist
bypassPermissionsSkips prompts apart from a few exceptionsOnly in isolated containers or VMs

Per the documentation, auto mode blocks by default, among other things, downloading and executing code such as curl | bash, sending sensitive data to external endpoints, force pushes and production deploys. Anthropic states plainly that auto mode reduces prompts but does not guarantee safety, and that bypassPermissions offers no protection against prompt injection. Both can be switched off with permissions.disableAutoMode and permissions.disableBypassPermissionsMode, most effectively in managed settings that users cannot override.

Rules: deny before ask before allow

Rules are evaluated in a fixed order: deny, then ask, then allow. A deny at any level cannot be overridden by another level, not even from the command line. The documentation itself names two limits:

For boundaries that don't depend on command text, Anthropic points to the sandbox.

The Claude Code sandbox

The sandbox isolates shell commands and their child processes at OS level, using Seatbelt on macOS and bubblewrap on Linux and WSL2. It is built on the open-source sandbox-runtime package. On native Windows, the documentation says commands run unsandboxed. The sandbox is off by default; turn it on with /sandbox or sandbox.enabled. What you need to know:

Anthropic sums it up: effective isolation needs both a filesystem and a network boundary. Without the network boundary, a compromised agent could exfiltrate SSH keys; without the filesystem boundary, it could backdoor its way to more access.

Cursor security: run modes and sandboxing

Cursor governs execution through run modes. Auto-review, which Cursor recommends, runs allowlisted calls straight away, other shell commands in the sandbox where possible, and sends the rest to a classifier. Allowlist runs only approved actions without asking; Run Everything runs every call with no sandbox and no classifier. Cursor states that Auto-review is not a security boundary and that the classifier can make mistakes. The sandbox uses Seatbelt on macOS and Landlock plus seccomp on Linux. Network access starts blocked and is opened according to the network mode; .git/config, .git/hooks, .vscode and .cursorignore are protected. Team settings take precedence over individual and project configuration.

Prompt injection via repositories, issues, web pages and dependencies

The OWASP Top 10 for LLM Applications 2025 lists prompt injection as LLM01 and distinguishes direct from indirect injection: in the indirect case, the instructions come from external content such as websites or files that the model processes. OWASP notes that it is unclear whether fool-proof prevention exists. For a coding agent, almost everything is external content:

An injected instruction becomes dangerous through the privileges the agent can use next: running a command, creating a config file, sending data to an outside address. OWASP covers this as LLM06 Excessive Agency and recommends limiting extensions and permissions to what is necessary and requiring human approval for high-impact actions. That is exactly what approval modes, deny rules and the sandbox are for.

Claude Code adds a few more layers: network commands such as curl and wget are not auto-approved, WebFetch usually hands Claude the answer of a separate model call rather than the raw page, and in Manual mode commands that Claude Code can't fully analyse trigger a prompt. Anthropic also advises against piping untrusted content directly to Claude and recommends running scripts that touch external services in VMs. For how injection works through MCP tool descriptions specifically, see our article on MCP prompt injection and tool poisoning.

MCP servers, plugins and skills as attack surface

Every MCP server you connect extends what the agent can do and feeds text into its context. Anthropic encourages writing your own MCP servers or using servers from providers you trust, and states that it does not security-audit or manage any MCP server. In Claude Code, servers from a project's .mcp.json need their own approval. The documentation points out, however, that more servers can come from user settings, connectors and plugins, so reviewing .mcp.json doesn't show everything a session loads.

According to its agent security documentation, Cursor requires approval for every MCP connection and then for each tool call, unless the tool is on an allowlist. A publicly documented case shows that an approval can be tied to a file that changes later:

Plugins and skills deserve the same care: in Claude Code, plugins can bring their own MCP servers and hooks, and skills can carry hooks and pre-approved tools. Treat them like any software you install. For hardening an MCP server itself, see our guide to securing MCP servers; for the risk classes at a glance, the OWASP MCP Top 10.

Hooks and configuration files in the repository

Hooks are shell commands that Claude Code runs automatically on certain events, with your environment and your privileges. They can live in .claude/settings.json inside the repository and get committed with it. That is useful for teams, and it is also why a third-party repository can run code on your machine once you start the agent in it.

Claude Code guards against this with the workspace trust dialog: in an untrusted folder, an interactive session asks first, and allow rules from the project only apply after you accept. Two details from the documentation matter:

CVE-2026-40068 shows why this boundary is worth attacking: according to NVD and Anthropic's advisory, a crafted repository could use a Git worktree file to bypass the trust dialog and immediately execute hooks from .claude/settings.json. The attacker had to know or guess a path the victim had already trusted. Fixed in version 2.1.84. On the Cursor side, CVE-2025-54135 (advisory) describes a chain in which indirect prompt injection made the agent create a missing .cursor/mcp.json, because creating a new dotfile didn't require approval. Fixed in version 1.3.9.

Both vendors have responded. Claude Code never auto-approves writes to protected paths such as .git, .claude, .vscode, .mcp.json, shell startup files and .npmrc; the exception is essentially bypassPermissions. Cursor requires approval for configuration files. Per its documentation, Cursor's workspace trust is disabled by default and can be enabled with "security.workspace.trust.enabled": true; in restricted mode, AI features don't work.

Secrets in context: .env files, keys and tokens

OWASP lists sensitive information disclosure as LLM02. With coding agents, the risk has two steps: a secret enters the context, for example because the agent reads a .env file to understand an error. From there it can end up in logs, commits or test files, or leave the machine via an injected instruction.

How secrets end up in Git and in frontend bundles is covered in our vibe coding security checklist.

Supply chain: packages, extensions, agent configuration

OWASP lists the supply chain as LLM03. With a coding agent it has three layers:

Claude Code security for teams: policy and hardening checklist

Individual developers can configure a lot themselves. It only becomes binding through centrally distributed settings: Claude Code offers managed settings that user and project settings cannot override, and Cursor offers team settings that take precedence over individual configuration. A team policy for AI coding agents should cover at least the following:

AreaMeasure
ModesDisable bypassPermissions centrally, and auto depending on your risk appetite; exclude Run Everything in Cursor via team settings
SandboxEnabled, with failIfUnavailable and no unsandboxed retries; network allowlist as narrow as possible
Read accessBlock ~/.ssh, cloud credentials and .env files via denyRead and Read deny rules
NetworkDeny curl and wget; allow destinations via WebFetch domains and the sandbox allowlist
MCPVetted servers only, list maintained centrally; no tools with write effects on the allowlist
Third-party repositoriesOpen in Manual or Plan mode first; run claude -p only with --bare or without project settings; enable workspace trust in Cursor
ReviewChanges to .claude/, .cursor/, .mcp.json, hooks and lock files need sign-off from a second person
SecretsNo production keys on machines running agents; short-lived development credentials
IsolationDev container or VM without access to your credentials for autonomous runs
OversightReview /permissions regularly; monitor usage via OpenTelemetry metrics; log settings changes with a ConfigChange hook

A starting point for a project-wide .claude/settings.json, built from the examples in the documentation. Adjust paths and domains to your project:

{
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)",
      "Bash(curl *)",
      "Bash(wget *)"
    ],
    "disableBypassPermissionsMode": "disable"
  },
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false,
    "filesystem": {
      "denyRead": ["~/.ssh", "~/.aws"]
    },
    "network": {
      "allowedDomains": ["registry.npmjs.org"]
    }
  }
}

Deny rules from the project apply immediately, even before the trust dialog, because they only restrict. For a policy nobody can loosen locally, put the same values into managed settings. For the organisational side of AI tool use, see our article on writing an AI acceptable use policy.

What a configuration file can't tell you

A clean settings file doesn't prove that it holds up in practice: whether an excludedCommands entry undermines the sandbox, whether an approved MCP server can do more than intended, whether a hook in the repository does something different after the next pull, or whether an instruction in an issue can talk the agent into leaking data. That only shows when someone tests the setup with an attacker's methods, within an agreed scope and on systems approved for testing.

How well are your coding agents locked down?

We assess how your team uses AI coding agents and MCP servers, within a scope agreed in writing: approval modes and managed settings, sandbox and network boundaries, connected MCP servers and plugins, hooks and configuration in your repositories, and prompt injection via issues, documentation and tool output. Every finding comes with reproducible evidence and a concrete fix. Learn more about AI pentesting and MCP security.

Request an AI agent security review

CyberSec42 is an independent technical security assessment, not an accredited certification body, and does not provide legal advice. CyberSec42 is not affiliated with Anthropic or Cursor.

Frequently asked questions

Is Claude Code safe to use?

Claude Code ships with approval prompts, deny rules, a trust dialog for new folders and an optional sandbox. How safe your setup is depends on how you configure them. Anthropic itself states that no system is completely immune to all attacks and recommends reviewing proposed commands before approving them.

Can Claude Code read my .env file?

Yes, if it sits in the working directory and no rule prevents it. A deny rule such as Read(./.env) blocks the built-in tools and recognised commands like cat. Against scripts that open the file themselves, only the sandbox with denyRead helps.

Which permission mode should I use?

Manual or Plan mode for third-party or sensitive repositories. For your own projects under Git, acceptEdits is a reasonable middle ground. Use bypassPermissions only in an isolated container or VM without credentials.

Does the sandbox protect against prompt injection?

It doesn't stop injection, but it limits the consequences: shell commands can only write to approved paths and only reach approved domains. Hooks, local MCP servers and the built-in file and web tools run outside the sandbox and need their own rules.

Are MCP servers vetted in Claude Code or Cursor?

Anthropic reviews connectors against its own criteria before listing them in its directory, but does not security-audit or manage MCP servers. Cursor requires approval for connections and tool calls. Choosing servers remains your responsibility.

Is it risky to open a third-party repository with a coding agent?

It can be. Hooks, MCP configuration and settings in a repository can trigger commands on your machine, and text in the repository can steer the agent. Open unfamiliar projects in Manual or Plan mode first, pay attention to the trust dialog, and use --bare or a container for automation.

Further reading

Sources