refusal rate
Subscribe

Coding agent prompt injection explained: how READMEs, issues and MCP output steer an agent, documented 2025-2026 incidents, and the controls that hold up.

[ fig. 01 — explainer ]48×5
[ fig. 01 — explainer ]16×5

Short answer

Prompt injection in a coding agent happens when text the agent reads, such as a README, issue, dependency output or MCP tool result, is treated as an instruction. Because the model can't reliably separate data from commands, the defense is architectural: sandbox execution, keep secrets out of reach, limit network egress, and require human approval for consequential actions. Running a local model doesn't change this.

OWASP ranking
LLM01, Prompt Injection
Study success rate
Up to 84% (Copilot, Cursor)
Rule of thumb
Max 2 of 3: untrusted input, sensitive access, external actions
Local model fixes it?
No

Key takeaways

  1. OWASP lists prompt injection as LLM01 and separates direct injection (the user's input) from indirect injection (files, pages and tool output the model ingests).
  2. A 2025 academic study of Copilot and Cursor, built on 314 payloads, reported attack success rates of up to 84% for malicious command execution.
  3. Documented 2025-2026 cases include a GitHub MCP data leak, a Cursor README attack, a maintainer-planted instruction in a library's test output (jqwik), and a GitHub Agentic Workflows leak.
  4. The mitigations that hold are controls outside the model: sandboxes, least-privilege tokens, egress limits, and approval gates. Guardrail prompts and denylists alone don't.
  5. A local model removes the cloud provider from the data path, not the injection risk. The attack works on whatever model reads the text.

What is prompt injection in a coding agent?

Prompt injection in a coding agent is untrusted text that the agent reads and then treats as an instruction. OWASP’s LLM01 entry defines it as input that alters a model’s behavior in unintended ways, and splits it into two kinds. In direct injection, the user’s own input changes the behavior. In indirect injection, the model ingests external content, such as a website or file, that contains instructions.

Coding agents are mostly an indirect-injection problem. They read files, dependency output, issues and web pages, and they hold tools that matter: a shell, a file system, git credentials, network access. In a chat window, a successful injection produces bad text. In an agent, it can produce a command.

The root cause is structural. Simon Willison’s lethal trifecta write-up puts it plainly: LLMs follow instructions wherever they appear in context and can’t reliably tell trusted instructions from malicious ones embedded in content. His comparison to guardrail products that claim to stop “95% of attacks” is worth keeping: in web security, 95% is a failing grade.

Where does untrusted input enter a coding agent?

Untrusted input enters through anything the agent reads that you didn’t write. That is more than it sounds like, because agents read automatically and at volume.

[ fig. 01 — The indirect-injection path in a coding agent, based on the OWASP and Willison descriptions cited below ]
Five kinds of untrusted input flow into one model context, which can drive shell, secrets and network tools; the controls have to sit outside the model.
  • Repository files. READMEs, contributing guides, code comments, config files and agent instruction files such as AGENTS.md in a repo you just cloned.
  • Issues, PRs and commit messages. Anyone can file an issue on a public repo, and an agent asked to triage issues will read all of them.
  • Dependency and tool output. Test runner output, build logs, package install messages and error text all flow back into the model’s context.
  • Web pages and docs. Anything fetched during research or while following setup steps.
  • MCP tool descriptions and results. A connected server’s descriptions and responses are context the model acts on. Anthropic’s own security docs note that it does not security-audit MCP servers and encourages writing your own or using ones from providers you trust.
  • Images and other media. Multimodal agents read pixels too, so any referenced image is input.

The pattern across all of them: the reader isn’t the author, and the agent doesn’t know the difference.

What incidents and research have documented it?

Documented cases now cover research, vendor disclosures and one deliberate in-the-wild stunt. None of the following needs an attack string to explain, and this page doesn’t include any.

DateCasePatternSource
May 2025GitHub MCP server leak, found by Marco Milanta and Luca Beurer-KellnerAn issue in a public repo steered an agent with access to private repos into writing private data into a public PRWillison
Jul 2025Cursor README attack, HiddenLayerHidden instructions in a README; command denylist bypassed; tools chained to exfiltrate data. Patched in Cursor 1.3HiddenLayer
Sep 2025AIShellJack study, 314 payloads against Copilot and CursorPoisoned development resources; up to 84% attack success for malicious command executionarXiv 2509.22040
May 2026jqwik 1.10.0 on Maven CentralMaintainer put an agent-targeted instruction in runtime output, hidden from humans with terminal control codesSnyk
Jun 2026Mozilla 0DIN proof of conceptClean-looking repo whose setup steps led an agent to fetch and run a payload at runtime, so nothing malicious was in the repo to scanHelp Net Security
Jul 2026GitLost, Noma LabsA public issue steered a GitHub Agentic Workflow with cross-repo read access into publishing restricted content; a small wording change got past the guardrailsInfoQ

The jqwik case is the one that shows intent. Per Snyk, a maintainer shipped a release that told coding agents to destroy work, then softened it after backlash, and at least one major agent recognized the instruction and refused to act. No credentials were stolen. It is still the first clear case Snyk knew of where a maintainer used prompt injection as a supply chain weapon.

For context on prevalence, a Google team that swept a public web archive for known injection patterns in early 2026 found mostly pranks, SEO manipulation and false positives, with only a small number of exfiltration or destruction attempts and limited sophistication. The same post reported the malicious category growing by a relative 32% between November 2025 and February 2026 (Google). In other words, the threat is real and the attackers are still early.

What do developers report in practice?

Developers report that the most dangerous variable is how much an agent is connected to, not how clever the payload is. These are community reports, quoted for color and not run as tests by this site.

  • In the Hacker News threads on jqwik, one commenter argued the stunt stayed contained only because the library is niche, and that the same move on a popular dependency would be a serious supply-chain event (HN comment). Another pointed out that a payload could sit in a transitive dependency the user never chose, and fire when an agent is asked to debug a project (HN comment).
  • A third thread ran in the opposite direction: a commenter argued the specific jqwik trick wouldn’t work on modern models (HN comment). That is plausible for one payload and one model. It is not a defense, since the attacker iterates and you don’t see the attempts.

Which mitigations actually work?

A commenter on the Hacker News launch thread for a rootless agent sandbox noted that a policy of read-only everywhere with writes only to the current directory prevents accidental damage such as a hallucinated rm -rf ~, but not injection, because it leaves SSH keys readable (HN comment). Commenters on the GitLost coverage made the same point from the other side: the risk is an agent wired to too much context and too-broad tokens, and a small wording change moved the request across the guardrail’s decision boundary (InfoQ). That is why the mitigations that work sit outside the model and limit what a hijacked agent can reach. OWASP’s own list includes least privilege, human approval for high-risk actions, segregating external content and adversarial testing, alongside constraining model behavior and filtering. The first group is enforced by software. The second relies on the model behaving.

ControlWhat it stopsCost / caveat
OS-level sandbox for shell commandsA hijacked command touching files or network outside allowed boundsSetup time. Anthropic’s docs say the sandbox holds regardless of what the model chose to run, but reads are open by default, and built-in tools, MCP servers and hooks run outside it
Network egress allowlistData leaving to an attacker’s serverBreaks tools that need arbitrary hosts
No secrets in the agent’s environmentCredential theft even after hijackNeeds a credential proxy or short-lived tokens
Least-privilege tokens, one repo at a timeCross-repo leaks like the GitHub MCP and GitLost casesLess convenient than one broad token
Human approval for shell, network and git pushConsequential actions you didn’t intendPrompt fatigue. Allowlist safe commands and keep prompts for the rest
Disposable VM or containerPersistence and lateral movementSlower start. Anthropic’s best-practice list for untrusted content includes running tool calls in VMs
Command denylists, system-prompt rulesLittle on their own: HiddenLayer’s Cursor research bypassed a denylistCheap, so fine as an extra layer, never the main one

Two design rules are worth memorizing. Willison’s lethal trifecta: don’t give one agent private data access, untrusted-content exposure and external communication at once. Meta’s Agents Rule of Two (October 2025) formalizes the same idea: until injection can be reliably detected, an agent in a single session should satisfy no more than two of three properties: it processes untrusted inputs, it accesses sensitive systems or private data, and it can change state or communicate externally. If a task needs all three, the source suggests a fresh session or human supervision.

[ fig. 02 — Agents Rule of Two, redrawn from Meta AI (Oct 31, 2025) ]
Three overlapping circles for untrusted input, private data access and external actions; any two are acceptable together, all three need a fresh session or human supervision.

The Mozilla finding adds one more: approval prompts help only if you can see what a command will actually do at runtime. Their recommendation is to treat setup scripts from unfamiliar repos as untrusted code even when the agent suggests running them.

Does running a local model help?

No. A local model keeps your code off a third party’s servers, but the injection works on whatever model reads the text. The mechanism Willison and OWASP describe is a property of how LLMs process context, not of where they run.

This is an inference from those sources, not a measurement. There’s also a specific caution for readers of this site. Abliterated and heavily fine-tuned open models have had refusal behavior removed or altered, and nothing guarantees that their resistance to injected instructions is better than the base model’s. Test your own model on your own workflows before assuming it is. Our local coding agent setup guide and Claude Code with a local model pages cover the tooling. The sandbox and egress rules above apply to them unchanged, and arguably matter more when the agent runs with your user’s full local permissions.

What is the checklist for teams adopting coding agents?

Start with blast radius, then add friction where it counts.

  1. Inventory what the agent can reach. Files, env vars, tokens, MCP servers, network. List them.
  2. Run it in a sandbox or disposable environment, and deny reads of ~/.ssh, cloud credential files and similar paths explicitly.
  3. Scope tokens per task. One repo, read-only unless a write is needed, short-lived.
  4. Apply the Rule of Two per session. If an agent reads public issues, it shouldn’t also hold private-repo write access.
  5. Gate consequential actions. Shell execution of unfamiliar commands, network calls, pushes and deletions need a human, with the real command visible.
  6. Treat unfamiliar repos and new dependencies as untrusted. Read setup steps before the agent runs them. Check CI and agent logs for unexpected text after dependency updates.
  7. Review diffs. Look for unexplained deletions and new outbound calls in agent-authored commits.
  8. Pin and review MCP servers. Prefer ones you wrote or can audit, and keep the list short.
  9. Run adversarial tests on systems you own, with authorization, as part of security research work or AI pentesting programs, never against third-party repos.
  10. Keep tools updated. Several of the cases above were patched by vendors after disclosure.

FAQ

What is prompt injection in AI coding agents?

It is the use of text in files, issues, dependency output or tool results to make an agent follow instructions its user didn’t give. OWASP calls the file-and-tool version indirect prompt injection.

Can prompt injection be fully prevented?

Not with current techniques. Guardrails reduce success rates, but they are probabilistic, so teams rely on sandboxing, least privilege and approval gates that limit damage when one succeeds.

Is MCP prompt injection different from other kinds?

The mechanism is the same, but MCP widens the surface: tool descriptions and tool results both enter the model’s context, and an agent with several servers may combine private data, untrusted content and outbound access. Anthropic’s docs advise using MCP servers you wrote or trust.

Does a sandbox stop prompt injection?

It doesn’t stop the model from being steered, but it limits what a steered shell command can touch. Per Anthropic’s docs, it doesn’t cover built-in tools, MCP servers or hooks, and reads are open by default unless you configure denies.

Are local LLMs safer against prompt injection?

They are more private, not necessarily safer. The vulnerability is in how the model treats context, so run local agents with the same sandbox, egress and approval controls as hosted ones.

Sources (10)
  1. LLM01:2025 Prompt Injection, OWASP Gen AI Security Project
  2. "Your AI, My Shell": Demystifying Prompt Injection Attacks on Agentic AI Coding Editors, arXiv 2509.22040
  3. GitHub MCP exploited: accessing private repositories via MCP, Simon Willison (May 26, 2025)
  4. The lethal trifecta for AI agents, Simon Willison (Jun 16, 2025)
  5. Agents Rule of Two: A Practical Approach to AI Agent Security, Meta AI (Oct 31, 2025)
  6. How hidden prompt injections can hijack AI code assistants like Cursor, HiddenLayer (Jul 31, 2025)
  7. jqwik 1.10.0 protestware and prompt injection, Snyk (May 2026)
  8. Mozilla warns of indirect prompt injection risk in AI coding agents, Help Net Security (Jun 29, 2026)
  9. GitLost: prompt injection leaks private repo data via GitHub Agentic Workflows, InfoQ (Jul 23, 2026)
  10. Claude Code security and sandboxing documentation, Anthropic

Keep reading

[ fig. 02 — guide ]18×8

How do security teams use AI for penetration testing?

Nov 2, 2026 · Guide

AI for penetration testing means using language models and agents to speed up work a tester is already authorized to do: reading code, triaging scanner output, analyzing logs, planning test steps and drafting reports. Research reviews describe it as early-stage and still human-supervised. The legal frame is unchanged: written authorization and a defined scope come first, and the model is only a tool inside both.

Read
[ fig. 03 — guide ]18×8

Can a local LLM power a coding agent?

Nov 2, 2026 · Guide

Yes. A local LLM can power a coding agent when it supports tool calling, holds at least 64,000 tokens of context and follows instructions across many steps. Open models such as Qwen3.8-27B, Qwen3-Coder-Next and Devstral Small 2 document agentic scores, and Aider, OpenCode, Cline and Goose all connect to local servers. Expect it to work on focused tasks and trail hosted models on large repositories.

Read
[ fig. 04 — how-to ]18×8

Can you use Claude Code with Ollama or another local model?

Oct 31, 2026 · How-to

Claude Code can talk to a local model because Ollama, LM Studio and llama.cpp each serve an Anthropic Messages endpoint, and Claude Code lets you change its base URL. It works with two or three environment variables. It is not an Anthropic-supported setup: the Claude Code docs say Anthropic doesn't support routing Claude Code to non-Claude models through any gateway.

Read