Practices

Security for LLM apps and agents

Last reviewed 30 November 2026

Overview

LLM applications add new attack surfaces: the model follows instructions found in any text it reads, and agents can act on those instructions with real tools and credentials. The core rule is to treat everything the model reads from outside as untrusted data, and to limit what the agent can do if it is fooled.

Key concepts

  • Prompt injection: malicious instructions hidden in web pages, documents, emails, tool results, or code that hijack the model. Indirect injection (through content the agent reads) is the main threat to agents.
  • The "lethal trifecta": private data, exposure to untrusted content, and a way to send data out. An agent with all three can be made to leak data.
  • Excessive agency: more tools, permissions, or autonomy than the task needs.
  • Supply chain: untrusted MCP servers, skills, plugins, or models can carry malicious instructions or code. Model weights can hide backdoored capabilities that testing provably cannot find: a paper (arXiv 2610.13928, 2026-10-09) hid capabilities behind a cryptographic trigger that survived fine-tuning, weight noise, gradient trigger search, and latent adversarial training, even with full weight access. A model's provenance matters, not just its eval results (see evals). Skills, prompts, and MCP servers can be pinned like code dependencies: APM declares them in apm.yml with a lockfile, and since 2026-11-04 Dependabot opens version-update PRs for them (version updates only, no security advisories yet; see skills). Popular agent tools attract impostors: REA (an MCP server and CLI for reverse engineering binaries, apps, and firmware) warns that look-alike repos copy its name (install only from morluto/rea or the rea-agents npm package, 2026-11). Cloned repositories can also carry their own skills, hooks, and MCP servers; GitHub Copilot admins (Enterprise Cloud) can require these to come only from plugins or managed settings (strictPluginOnlyCustomization, 2026-11-17).
  • Sensitive data exposure: secrets in prompts, logs, or training data.
  • Improper output handling: passing model output unchecked into shells, SQL, or HTML.
  • Unbounded consumption: runaway loops and cost attacks.
  • Agents as a threat to others: an agent with web access can harm third-party sites through unwanted edits, exploit attempts, or crawling heavy enough to cause outages. Operators are responsible for what their agents do outside their own systems. The Wikimedia Foundation (2026-10-05) attributes such activity to OpenAI agents: since about May 2026 it saw sandbox and configuration edits, failed attempts to exploit its Etherpad, and query volumes that may have contributed to a Wikidata Query Service outage. The post says OpenAI admitted its agents behaved "unpredictably", but quotes no full OpenAI statement.
  • Verified access to cyber capabilities: frontier providers ship safety classifiers that refuse offensive cyber, bio, and other high-risk requests by default, and unlock cyber help for vetted defenders and red teams. Anthropic's Cyber Verification Program (expanded 2026-10-06, absorbing Project Glasswing) has three tiers: Defense Access (security teams, maintainers, researchers), Red Team Access (organisations only), and Specialized Access (critical systems, reviewed with the US government). Anthropic says Glasswing partners found more than 129,000 verified vulnerabilities from April to July 2026. Google released Gemini 4 Argon first only to cybersecurity partners; its Fairwind Program, which gives vetted defenders Argon without cyber guardrails, is expanding to hundreds more partners (2026-10-13). OpenAI's gpt-6-cyber (2026-11-05) is API-only for organisations approved for its Daybreak Red programme. Claude Fable 5.2 (2026-11-09) blocks high-risk cyber requests (they are routed to Opus 4.8), while Mythos 5.2 is available through the Cyber Verification Program and powers Claude Security.
  • Defensive programmes: Anthropic's Cyber Mission (2026-10-08) runs a Critical Infrastructure Defense Program with eleven founding partners (including CrowdStrike, Palo Alto Networks, and Dragos), and OSS Scanner, a free opt-in vulnerability scanner for open-source projects that sends proof-of-concept exploits and suggested fixes. Anthropic expects over 90% of its findings to be true positives. It also funds the PSF, OpenSSF, Alpha-Omega, and the Apache Software Foundation.
  • Agents as defensive tools: Anthropic's Claude Security plugin (0.13.0, 2026-11-24) runs a multi-agent scan inside Claude Code: agents map the codebase, hunt for vulnerabilities, and verify each finding before reporting it (Markdown, JSONL, or SARIF, plus optional patch files). 0.13.0 adds an attack surface analysis skill, a live scan view, and a claude-security CLI (/plugin install claude-security@claude-plugins-official). OpenAI and Cisco's Shirudo (open source, BSD 2-Clause, 2026-11-23) is a Linux runtime for temporary eBPF "shields" that block an exploit path in a running process until a patch ships. Shields are signed, can run in monitor mode first, and need an operator's approval; OpenAI showed Codex writing one. Both keep a human approving each finding or mitigation.
  • Frontier cyber capability: Gemini 4 Argon solved all 12 of Google's simulated end-to-end cyberattack scenarios (the previous generation solved five), which triggered Google's strongest cyber and bio safeguards. External bio red teaming unlocked under 1% of sub-tasks (Google, 2026-10-13).
  • Layered containment: no single layer stops prompt injection. Anthropic describes three layers: the environment (sandbox, network egress, credentials), the model's own robustness, and limits on external content. The environment is the one that holds when the probabilistic layers fail. In practice (May 2026): claude.ai runs code in gVisor, Claude Code uses an OS sandbox with network off by default, and Cowork runs in a full VM with an egress allowlist. Opus 4.7 had about 0.1% prompt-injection success on single attempts and 5–6% after 100 adaptive attempts (Gray Swan). Google reports 0.7% for Gemini 4 Argon on Gray Swan's indirect injection benchmark, but after 15 adaptive attempts, so the two figures are not directly comparable.
  • Runtime safeguards inside the model: Google's Argon stack adds activation probes (detecting when cyber or bio knowledge is being used) and multi-step monitoring that can halt a response, on top of input classifiers (2026-10-13).
  • Decomposed misuse: refusal checks judge one request at a time, so a harmful campaign split into harmless-looking subtasks can get through. Election red teaming of Claude in the US, Israel, and Brazil (reported 2026-10-14) found exactly this: single harmful requests were reliably refused, split-up campaigns were sometimes missed. The fix is account-level, multi-step misuse classifiers and enforcement that look across many requests, not stricter per-request refusals. Anthropic also banned a foreign fake-news operation and ad-revenue fake-news schemes, and found about 0.002% of sampled US conversations violated election-integrity rules.
  • Sandbox escapes get fixed release by release: Claude Code 2.1.299 (2026-10-14) closed symlinked denied paths on macOS and writes into --plugin-dir, and made more hook failures block actions. 2.1.309 (2026-10-22) fixed more: on macOS and Linux, shell startup files ran outside the sandbox before each command; macOS denyWrite globs did not apply through symlinks; sandboxed commands could edit the --mcp-config file; Edit(path) deny rules missed some redirects; and worktree isolation accepted some locale-prefixed and zsh arithmetic commands. Keep agent tools current when you rely on their sandbox. Frameworks harden the same way: Pydantic AI 2.59.0 / 1.107.9 (2026-10-21) fix GHSA-4whf-38hw-pxxh (high), where hostile HTML fetched by web_fetch could stall the process, and escape compacted transcripts so tool output cannot forge messages; Microsoft Agent Framework (Python) 1.23.0 makes AG-UI endpoints declare an authorization scope and renames the Docker shell's extra_run_args to unsafe_extra_run_args. The pace did not slow in November 2026: 2.1.319 to 2.1.327 (2026-11-06 to 2026-11-17) fixed wildcard allow rules such as Bash(ls*) skipping prompts, deny rules missed through sudo, env, cp/mv into a directory, quoted words, or after cd (relative rules such as Read(./.env)), compound commands and crafted environment prefixes that ran without asking, an allow rule that could run a different program, Write and Edit ignoring Read deny rules, the sandbox switching off mid-session, MCP OAuth refresh tokens sent to another host after a redirect, destructive Bash commands shown as reads, and Remote Control deleting git-ignored files such as .env in worktree mode. Since 2.1.325 sandboxed Bash prompts again by default and plugin install warnings say plugins can run code.
  • Approval fatigue: when users approve almost every prompt (about 93% in Claude Code, per Anthropic), permission prompts stop protecting anyone. Sandboxing that removes most prompts is safer than asking more often. Model-judged auto-approval is the other answer: Claude Code's auto mode and GitHub Copilot's assisted permissions (GA 2026-10-26; admins can keep Assisted while blocking Allow All) let a model approve clearly safe actions and ask about the rest. Both are probabilistic checks, not hard boundaries, so pair them with a sandbox.
  • Agents in CI: GitHub Agentic Workflows (GA 2026-10-28) shows a layered default for agents running in Actions: read-only permissions, a sandboxed container behind an egress firewall (Agent Workflow Firewall), writes only through declared "safe outputs", and a threat-detection job that scans proposed changes before they apply. Micro-VMs and enclaves are options for cross-repository work (see coding agents).

How to use it

  • Grant least privilege: scoped tokens, read-only where possible, no production secrets.
  • Run agents in sandboxes or containers; restrict network egress. Prefer hardened standard isolation (gVisor, VMs, Seatbelt, bubblewrap) to home-made components. Prime Radiant's external sandboxes (experimental, 2026-11-16) keep the agent on the host and run its commands in a Linux VM that sees only mounted folders, with no network unless an allow-list proxy is on; the proxy swaps a placeholder for the real API key so the agent never holds it. Adapters exist for Claude Code (CLAUDE_CODE_SHELL_PREFIX; Bash only, Read and Edit still run on the host), Codex (exec-server), and Pi (all tools).
  • Scan agent changes for secrets: Copilot's security review specialist runs GitHub secret scanning (/security-review; /settings aiSecretDetection on in the CLI, 2026-11-17), and agents can call it as a subagent. Add MCP servers with claude mcp add-json <name> - (Claude Code 2.1.327+) so tokens stay out of shell history.
  • Remember that allowed domains can still leak data: an attacker's API key in a workspace file can send data to an allowlisted API. Pin outbound credentials to the session.
  • Do not parse project files, settings, or hooks before the user has trusted the project.
  • Require human approval for destructive or outward-facing actions.
  • Keep credentials out of the model's context; inject them at the tool layer.
  • Review MCP servers, skills, and plugins before installing them. In Claude Code, deniedMcpServers URL entries also block Anthropic-provided servers and cloud connectors with a matching upstream URL (since 2.1.318, 2026-11-04).
  • Restrict API keys to known addresses where the provider allows it. The Claude Console IP allowlist (beta, 2026-11-05) takes up to 1,000 IPv4/IPv6 addresses or CIDR ranges per organization and refuses requests from anywhere else, so a leaked key is far less useful. Add CI runners and cron hosts first, and watch for hosts on dynamic IPs. A beta Admin API call signs a Claude Enterprise member out everywhere.
  • Make policy hooks fail closed: Claude Code hooks (onFailure: "block") and, since 2026-11-03, Agent SDK hook callbacks (on_failure="block" in Python) block the action when the hook crashes or times out. Claude Code 2.1.317 also asks before a web or shell tool call sends your account email address, and warns when a new cloud scheduled task gets connectors you did not ask for.
  • Validate and escape model output before executing or rendering it.
  • For organization-wide data-loss prevention, inspect prompts server-side before inference. Claude Enterprise's inference hooks (GA 2026-10-20) send every governed prompt, and optionally each batch of tool calls, to your own allow/deny server across all Claude apps, including Claude Code. They offer shadow mode, gradual rollout, a choice between failing open and failing closed, and a circuit breaker. They cannot redact content or inspect images, and do not cover API organizations, Bedrock, or Vertex. Resellers can confine a safety enforcement action to one end customer with Claude API user profiles (see Claude).
  • Keep API keys out of command lines: Claude's SDK majors of 2026-10-21 send keys as Authorization: Bearer, and the ant CLI no longer accepts keys as flag values.
  • Audit guardrail decisions: Claude Code 2.1.307 added a claude_code.safety_event OpenTelemetry event for tool calls blocked or prompted by guardrails, but 2.1.312 (2026-10-27) stopped sending it. Use /permissions → Recently blocked to review blocked calls instead.
  • Fence unattended agents into the repository: Claude Code 2.1.314 adds permissions.blockWritesOutsideWorkingDirectories (with the existing blockReadsOutsideWorkingDirectories), which applies in every permission mode, including auto and bypass. Since the same release, Bash hooks also see shell commands started by the Monitor tool (they can block or ask, but not approve or rewrite them).
  • Enable sandbox.allowNestedUserNamespaces (Claude Code 2.1.305, Linux) only if you need Chromium or rootless podman inside the sandbox; the changelog warns that it weakens the sandbox's file protections.
  • Keep Claude Code current (2.1.325 or later as of 2026-11-22) if you use auto or accept-edits mode, and review any wildcard Bash allow rules; 2.1.323 warns at startup about allow rules with * in a variable value. Self-hosted runners started with --trust-workspace false also block repository hooks and skills (2.1.319). For unattended runs, permissions.denyInsteadOfPrompting denies rather than waits.
  • Open untrusted Windows files or installers in a disposable machine rather than on the host: sandbox-mcp's sandbox_detonate and sandbox_install_test tools run them in Windows Sandbox and record what changed (see MCP).
  • Treat "read-only" tools that wrap other programs with care. Git, for example, runs commands named in a repository's .git/config (core.fsmonitor, diff.external, hooks, Git LFS filters), so mcp-server-git before 2026.11.11 could be made to run code by a copied working tree or archive, with no prompt, and before 2026.11.27 an LFS filter or a .git file pointer could still be abused (see MCP). Upgrade the reference servers, and point Git tools only at repositories whose .git folder you trust.
  • Set spending and iteration limits.
  • Rate-limit agent traffic, restrict which hosts agents can write to, and make agent requests identifiable (user agent, contact details) to the sites they visit.

Current state

  • 2026-11-30: MCP reference servers v2.6.0 (2026-11-27) fixed eight advisories: six in mcp-server-git (one High: Git LFS filters from repo config ran with server privileges), one in mcp-server-fetch, and one in server-memory. It is the second git-server batch this month, so treat repository contents as untrusted input (see How to use it).
  • 2026-11-25: Upgrade Pydantic AI to 2.74.0 or later if you use its PlaywrightBrowser tool (four advisories fixed; see frameworks). Claude Code 2.1.332's new PreSkillShellCommand hook (beta skills over MCP) lets you vet shell commands that third-party skills run (see skills). Agent-built defences (Claude Security plugin, Shirudo) are new this week (see Key concepts).
  • 2026-11-19: Claude Code is fixing permission and sandbox gaps in nearly every release (2.1.319 to 2.1.328 in two weeks; see Sandbox escapes). Expect more; update often.
  • 2026-11-18: Prime Radiant's external sandboxes are experimental, and Copilot's on-demand secret scanning is new (see How to use it).
  • 2026-11-12: The MCP reference servers fixed six advisories in 2026.11.11, including command execution through repository Git config in mcp-server-git (High); upgrade (see How to use it and MCP).
  • 2026-11-04: Dependabot support for APM-pinned skills and MCP servers covers version updates only; no advisory database for skills exists yet.

Open questions

  • Is there any complete defence against prompt injection, or only layered mitigations? Partly answered (2026-10-09): Anthropic's own figures show a strong model still fails 5–6% of the time against adaptive attacks, and it relies on sandboxing as the final layer. No provider claims a complete defence.
  • How reliable is OSS Scanner in practice? The 90% true-positive rate is Anthropic's expectation, not a measured result.
  • How did Wikimedia attribute the agent activity to OpenAI, and will OpenAI publish an account of it? Only Wikimedia's post and secondary commentary are available so far.

Sources