Agentshield

Claude Agent Security: Claude Code Security, Agent SDK Hardening, and Runtime Controls

Anthropic ships more built-in security than any other agent runtime. It is also explicit that the permission system is a gate, not a sandbox, and that it protects one developer on one machine.

OWASP LLM Top 10 Immutable audit trail Never trains on your data

Direct answer

Claude agent security means keeping Claude Code and Claude Agent SDK deployments from doing damage with the access an engineer granted them. Anthropic ships genuinely strong defaults: read-only permissions until you approve otherwise, a working directory boundary, an OS-level bash sandbox, isolated context windows for web fetches, and fail-closed matching on anything unrecognised. Anthropic is also unusually direct about the limits. Its deployment guide states that command parsing "is a permission gate, not a sandbox; it does not infer whether a command is dangerous from its target path or effects," and the security documentation adds that "no system is completely immune to all attacks." Two structural gaps remain after you have configured everything correctly. Trust verification is disabled when Claude Code runs non-interactively with the -p flag, which is exactly how it runs in CI. And every control is configured per repository by the engineer who owns it, so nobody can answer what forty agents across five teams are collectively allowed to do. Agentshield sits outside the agent process and closes both: one policy that applies whether or not a developer configured it, and one audit trail across every Claude agent you run.

Try it live

Watch Agentshield block an attack in real time.

Pick a scenario and drive the inspection lane yourself. No signup needed.

Threat Console
12,408 injections blocked this week

Run a request

Inspection lane

INSPECTING
untrusted input

Policy trace

High-risk action held for approval

Audit trail

The risk

Engineering adopted Claude Code in a week and it worked. Now it runs in six repositories, three CI pipelines, and a scheduled job nobody documented. Each repo has its own settings file with its own allow rules, written by whoever set it up. Security has been asked to sign off on the rollout and cannot answer the first question: across all of it, what can these agents actually reach, and what did they do last month?

How Agentshield handles it

Agentshield is stack-neutral and sits in the request and action path, so Claude Code, the Claude Agent SDK, and your MCP servers keep working exactly as configured. Anthropic keeps enforcing its own in-process controls; we add the layer outside the process. Untrusted content, whether it came from a fetched page, a repository file, a tool result, or an MCP server response, is inspected for injection before the agent acts on it. Every tool call is checked against a permission scope attached to that agent rather than to the developer who launched it. Irreversible actions are held for a human. Everything lands in one append-only record, including the calls that were denied.

The controls

The controls that secure the Claude Code and Claude Agent SDK deployments your engineers are already running.

What is Claude agent security?

Claude agent security covers two products that people often discuss as one. Claude Code is the coding agent your engineers run in a terminal, an IDE, or the browser. The Claude Agent SDK is the library teams use to build their own agents on the same runtime, which then run wherever you deploy them. They share a permission model and a threat model, and they fail in different places because a developer watching a terminal is a control that a scheduled job does not have.

The underlying issue is the one every agent framework has. Anthropic states it plainly in its deployment guide: unlike traditional software that follows predetermined code paths, these tools generate their actions dynamically based on context and goals, so their behavior can be influenced by the content they process. A README with unusual instructions in it becomes an instruction. So does a web page, a dependency changelog, a Jira ticket, or a tool description served by somebody else's MCP server.

What makes Claude different from the rest of the field is that Anthropic did not leave this entirely to you. Claude Code starts read-only and asks before it writes. It parses bash commands into an abstract syntax tree and matches them against your rules rather than doing string comparison. Web fetches run in an isolated context window so retrieved content cannot address the main conversation directly. Web search results are summarized instead of pasted in raw. Unmatched commands fail closed. That is a serious set of defaults, and any honest comparison should say so.

The reason a runtime control layer still matters is not that those defaults are weak. It is that they are per developer, per machine, and per repository, and they are configured by the same person whose productivity they slow down.

Claude Code security: what Anthropic enforces by default

This is the honest inventory, taken from Anthropic's own security documentation rather than from a comparison chart. If you are evaluating Claude Code, assume all of it is on before you add anything.

ControlWhat it doesWhat it does not do
Read-only by defaultClaude Code uses strict read-only permissions until you approve an action. Editing files, running tests, and executing commands each require explicit permissionReading is itself a risk. A read-only agent that can reach a .env file and then make a network call has everything it needs
Working directory boundaryWrites are confined to the folder Claude Code started in and its subfolders. Parent directories need explicit permissionSays nothing about what the code inside that folder is allowed to do once it runs
Command parsing into an ASTBash commands are parsed and matched against your rules. Constructs such as eval always require approval regardless of allow rulesAnthropic's own wording: this "is a permission gate, not a sandbox; it does not infer whether a command is dangerous from its target path or effects"
Sandboxed bash toolOS-level filesystem and network isolation using Seatbelt on macOS and bubblewrap on Linux, configured with the sandbox commandShares the host kernel, and the network proxy allowlists by hostname without inspecting TLS, so domain fronting is possible
Isolated context windowsWeb fetch runs in a separate context window so fetched content cannot inject directly into the main conversation. Search results are summarized rather than pasted rawContent that arrives through a file, a tool result, or an MCP server response does not get this treatment
Fail-closed matchingCommands that do not match an allow rule, or that cannot be parsed cleanly, require manual approvalDepends on a human being present to approve. See the CI section below
Trust verificationFirst-time codebases and newly added MCP servers require explicit trust before runningExplicitly disabled when running non-interactively with the -p flag
Secure credential storageAPI keys are held in the macOS Keychain where available, and protected by file permissions on LinuxProtects the Claude credential, not the AWS, database, or git credentials sitting in the environment the agent runs in

Anthropic closes its security page with a line worth quoting to anyone who thinks a vendor default is a finished control: "While these protections significantly reduce risk, no system is completely immune to all attacks." That is the correct posture, and it is also the argument for defense in depth.

Claude Code security risks: where the built-in controls stop

Every item here is a consequence of how the product is designed for a single developer, not a defect. They become problems at the point where an organisation, rather than an individual, has to answer for the deployment.

  • The approval gate assumes somebody is watching. Fail-closed matching, trust verification, and command injection detection all resolve to a prompt. In an interactive terminal that is a real control. In a scheduled job, a CI pipeline, or a headless Agent SDK service, there is nobody to answer it, and teams reach for broader allow rules or the flag that skips permissions entirely to make the job run.
  • Trust verification is off in the mode CI uses. Anthropic documents that trust verification is disabled when running non-interactively with the -p flag. That is precisely the mode automation runs in, which means the check that would have flagged a new MCP server or an unfamiliar codebase is not running where the human review is also absent.
  • Configuration is per repository and owned by engineering. Allow rules live in settings files checked into source control. Loosening one is an ordinary-looking pull request reviewed by application reviewers. Nothing about the diff announces itself as a policy change, and there is no fleet-wide view of what the current effective policy is.
  • Read access is the underrated risk. Anthropic's deployment guide lists the files that leak even under a read-only mount: .env files, git credentials, AWS and Google Cloud credential files, kubeconfig, npm and PyPI tokens, and private keys. An agent that can read those and reach the network does not need write access to hurt you.
  • The sandbox shares a kernel and does not inspect TLS. Anthropic says both things directly. Sandboxed processes share the host kernel, so a kernel bug is an escape path, and the built-in proxy allowlists domains by the hostname the client supplied without terminating TLS, so code inside the sandbox can potentially reach hosts outside the allowlist.
  • Logs are developer logs. OpenTelemetry metrics tell you usage. They are not an append-only, per-decision record of which tool call was requested, whether policy allowed it, and who owned the agent that asked. That distinction is the whole of agent audit trail.

None of this argues against running Claude Code. It argues for putting a control point where the developer's configuration is not the last word. The general version of that argument is on AI runtime security, and the coding-agent-specific version is on securing coding agents.

Claude Agent SDK security: isolation options compared

When you build on the Claude Agent SDK, your agent runs on your infrastructure and the terminal prompt disappears. Anthropic publishes a deployment guide for exactly this case, and it is refreshingly unromantic: the same principles that apply to running any semi-trusted code apply here, meaning isolation, least privilege, and defense in depth. The four isolation technologies it compares, with the tradeoffs Anthropic itself gives:

TechnologyIsolation strengthOverheadBest for
sandbox-runtimeGood, with secure defaultsVery lowSingle developers and CI jobs. Filesystem and network limits via bubblewrap or Seatbelt, configured with a JSON allowlist, no Docker required
Containers (Docker)Setup dependentLowMost production services. Strength depends entirely on the flags, which is why the guide publishes a hardened example
gVisorExcellent with correct setupMedium to highMulti-tenant or untrusted content. Syscalls are intercepted in userspace. CPU-bound work is roughly free, heavy file I/O can be 10 to 200 times slower
VMs (Firecracker, QEMU)Excellent with correct setupHighHard tenancy boundaries. Firecracker boots in under 125ms with under 5 MiB of memory overhead

The single most useful pattern in that guide is not an isolation technology at all. It is the credential proxy. Rather than handing the agent an API key, you run a proxy outside the agent's boundary that injects the credential into outbound requests. The agent can call the API and never sees the secret, the proxy enforces an endpoint allowlist, and every request is logged in one place. Combined with a container started with no network interfaces at all, where the only route out is a mounted Unix socket to that proxy, a compromised agent cannot exfiltrate to an arbitrary server because it has nowhere to send it.

One practical trap: not every program respects the proxy environment variables. Anthropic notes that Node.js fetch ignores them by default, and that Node 24 and later need an explicit environment flag to honour them. An agent that bypasses your proxy is an agent outside your allowlist. Broader guidance on isolating agent execution is on AI agent sandboxing, and the step-by-step version is in how to sandbox an AI agent.

Claude Code MCP security: the part Anthropic does not own

Claude Code connects to Model Context Protocol servers, and this is the sharpest boundary in the whole product. Anthropic's security documentation draws it explicitly: Anthropic reviews connectors against its listing criteria before adding them to the Anthropic Directory, but does not security-audit or manage any MCP server. Directory presence is a listing decision, not a security assurance, and anything you add yourself carries no review at all.

That matters because tool descriptions are prompt input. Invariant Labs documented tool poisoning in April 2025 as malicious instructions embedded within MCP tool descriptions that are invisible to users but visible to AI models, with a proof of concept that exfiltrated a Cursor MCP config file and an SSH private key. The Cloud Security Alliance followed in July 2026 with a study of more than 45 real-world MCP servers reporting attack success rates above 60 percent and peaking at 72.8 percent. CVE-2025-54136, rated CVSS 8.8, captured the structural version of the problem: approving a tool definition once does not bind the server to that definition later.

Three controls close most of it, and only the first is native to Claude Code. Keep your allowed server list in version control, as Anthropic recommends, so adding a server is a reviewed change. Pin tool definitions by SHA-256 hash so a silent server-side rewrite fails instead of executing. And treat everything an MCP server returns as untrusted content that gets inspected before the agent acts on it, which is the same rule you apply to a fetched web page. The full treatment is on MCP server security, and the architecture that enforces it centrally is on MCP gateway.

Claude agent security best practices

This is the sequence we recommend to teams running Claude Code or Agent SDK services at more than one team's worth of scale. The first four are Anthropic's own guidance and cost nothing but an afternoon.

  1. Turn on managed settings. Organisation-level policy files apply across users instead of relying on each engineer's local configuration. Pair them with ConfigChange hooks so settings edits during a session are audited or blocked outright.
  2. Enable the bash sandbox before you widen allow rules. Teams usually loosen permissions to stop the prompts. Sandboxing removes most prompts without removing the boundary, which is the trade you actually wanted.
  3. Sanitize what you mount. Exclude .env files, cloud credential directories, kubeconfig, registry tokens, and private keys from anything the agent can read, including read-only mounts. Copy in the source files needed rather than mounting a home directory.
  4. Put credentials behind a proxy. The agent should be able to call the service without ever holding the key. This is the highest-value change in the entire Anthropic deployment guide and it also gives you a single log of outbound calls.
  5. Give each agent its own identity. Not native to Claude Code, where an agent inherits whatever the launching developer or service account holds. Without it, attribution afterwards is guesswork. See AI agent identity.
  6. Treat headless runs as a separate risk tier. Anything running with the -p flag has no trust verification and no human to approve a prompt. Give those runs their own narrower policy rather than the interactive one.
  7. Gate irreversible actions on a human. Production writes, deletions, payments, and outbound messages should stop for approval regardless of which repository the agent was launched from. See human in the loop AI agents.
  8. Run in observe mode first. Two weeks of watching what your Claude agents actually call is worth more than a policy written from imagination, and it makes the switch to enforce uneventful. See tool permissions.
  9. Keep one trail across every agent. One append-only record covering Claude Code, Agent SDK services, and anything built on another framework, so a question about last Thursday has one place to be answered.

Steps one through four are configuration you should do today whether or not you ever buy anything. Steps five through nine need a control point outside the agent process, because each one is a property no per-repository setting can guarantee across teams.

How Claude agent security compares to LangChain and MCP-only setups

Teams rarely run one framework. The useful comparison is not which is safest but which controls each one gives you for free, so you know what you are still on the hook for. If the other tool in your estate is Google's, the equivalent inventory is on Gemini CLI security, and we compare the two directly in Gemini CLI vs Claude Code.

PropertyClaude Code and Agent SDKLangChain and LangGraph
Default permission postureRead-only until approved, fail-closed on unmatched commandsWhatever was passed into the tools list. No default gate
Injection handling on fetched contentIsolated context window for web fetch, summarized search resultsNone by default. Guardrail middleware is opt-in per agent
Execution isolationBuilt-in OS-level bash sandbox, plus a documented container and VM pathYour own containerisation. Nothing built in
Known CVE exposureReported through a HackerOne program. No comparable public CVE wave to dateA 2025 to 2026 wave across separately versioned packages. See LangChain security
Per-agent identityNot native. Inherits the launching user or service accountNot native. Usually one shared service account
Fleet-wide policyManaged settings help, still per-repository in practiceNone
Independent audit recordUsage telemetry, plus full audit logging in Anthropic-hosted cloud sessionsApplication logs

Claude wins the top half of that table outright, and it is worth choosing on those grounds. The bottom three rows are identical for both, and they are the rows a security owner is judged on. That is the gap we fill, and we fill it the same way for both, which is the point of being stack-neutral. If OpenAI is the third framework in your estate, the equivalent breakdown of its guardrail scoping rules is on OpenAI agent security.

FAQ

Common questions about claude agent security.

Is Claude Code safe to use at work?

For most teams yes, with configuration. Claude Code is read-only by default, confines writes to its working directory, sandboxes bash commands at the OS level, and fails closed on commands it cannot match. The risks that remain are organisational rather than technical: policy lives per repository, headless runs skip trust verification, and there is no fleet-wide record of what every agent did.

What are the main Claude Code security risks?

Four dominate. Prompt injection arriving through files, fetched pages, tool results, or MCP servers. Read access to credential files such as .env, cloud credentials, and private keys. Headless runs with the -p flag, where trust verification is disabled and no human answers approval prompts. And per-repository configuration, which makes fleet-wide policy and attribution impossible.

Does Claude Code protect against prompt injection?

Partly, and more than most. Web fetch runs in an isolated context window, search results are summarized rather than pasted raw, sensitive operations need approval, and suspicious commands require manual approval even when previously allowlisted. Anthropic still states directly that no system is completely immune. Content arriving through files, tool results, and MCP responses is not isolated the way web fetches are.

What is the difference between Claude Code and the Claude Agent SDK for security?

Claude Code usually runs interactively, so approval prompts are a real control. The Agent SDK builds services that run on your infrastructure with no human present, which turns every prompt into either a blocked job or a widened allow rule. SDK deployments therefore need isolation and a credential proxy rather than relying on the permission gate.

Is the Claude Code sandbox enough on its own?

It is a strong default and not a complete boundary. Anthropic notes two limits: sandboxed processes share the host kernel, so a kernel vulnerability is an escape path, and the network proxy allowlists domains by client-supplied hostname without terminating TLS, so techniques such as domain fronting can reach hosts outside the allowlist. Use gVisor or a VM when the threat model needs more.

How do I secure Claude Code in CI?

Treat it as a distinct risk tier. Trust verification is disabled with the -p flag and nobody can answer an approval prompt, so give CI runs their own narrow policy rather than inheriting the interactive one. Run inside a container with no network interfaces, route outbound calls through a credential-injecting proxy, and mount source read-only with credential files excluded.

Are MCP servers in Claude Code audited by Anthropic?

No. Anthropic reviews connectors against listing criteria before adding them to its Directory but states that it does not security-audit or manage any MCP server, and servers you add yourself get no review at all. Keep the allowed list in version control, pin tool definitions by hash, and treat tool descriptions and responses as untrusted input.

What is claude managed agents security?

Managed settings let an organisation enforce permission policy across all users instead of leaving it to each engineer local configuration, and ConfigChange hooks can audit or block settings changes mid-session. It is the strongest native answer to fleet-wide policy. It still governs the Claude client rather than every agent in the estate, whatever framework built them.

Does Agentshield replace Claude Code permissions?

No, and you should keep them on. Anthropic in-process controls are the inner layer and they are good. Agentshield adds the outer layer: policy that applies whether or not an engineer configured the repository, injection inspection on content Claude does not isolate, approval gates that survive headless runs, and one audit trail across every Claude agent and every other framework you run.

How do I secure a Claude agent in production?

Enable managed settings and the bash sandbox, exclude credential files from anything mountable, and put API keys behind a proxy so the agent never holds them. Then give each agent its own identity, route its calls through a control point in observe mode for two weeks, scope permissions from what you actually saw, gate irreversible actions on a human, and switch to enforce.

Secure your claude agent security.