---
title: "Prompt injection against coding agents: attack paths and defenses"
type: guide
url: https://agentsfordevs.com/guides/prompt-injection-coding-agents
markdown: https://agentsfordevs.com/guides/prompt-injection-coding-agents.md
publisher: Agents for Devs
author: Agents for Devs desk
reviewed_by: Agents for Devs desk
published: 2026-12-06
updated: 2026-12-06
license: https://agentsfordevs.com/reuse
citation: 'Agents for Devs. "Prompt injection against coding agents: attack paths and defenses." Published Dec 6, 2026. https://agentsfordevs.com/guides/prompt-injection-coding-agents'
attribution: Credit Agents for Devs and link to https://agentsfordevs.com/guides/prompt-injection-coding-agents
format: Guide
topics:
  - security
description: Where prompt injection reaches Claude Code, Codex, Grok Build and Copilot cloud agent, and the documented settings that limit the damage.
---

# Prompt injection against coding agents: attack paths and defenses

Coding agents read issues, files, web pages and tool output, and any of it can carry instructions. This guide maps where injected text gets in and which documented settings limit what a hijacked agent can do.

## Short answer

Prompt injection against a coding agent happens when text the agent reads while working, such as an issue, a README, a web page, a tool result or a tool description, carries instructions the agent follows with your access. OWASP lists prompt injection as LLM01 in its 2025 Top 10 and says it is unclear whether fool-proof prevention exists. Defend by limiting the blast radius: approval prompts on writes and network calls, an OS sandbox, denied secret paths, blocked egress and human review before merge.

**Checked against:** OWASP's [LLM01:2025 Prompt Injection](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) and [LLM06:2025 Excessive Agency](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/), Anthropic's Claude Code [security](https://code.claude.com/docs/en/security), [permissions](https://code.claude.com/docs/en/permissions) and [sandboxing](https://code.claude.com/docs/en/sandboxing) docs, OpenAI's [Codex approvals and security](https://learn.chatgpt.com/docs/agent-approvals-security) page, Grok Build's [run modes](https://docs.grok.com/build/agents-window/agent/security/run-modes) page and GitHub's [Copilot cloud agent risks](https://docs.github.com/en/copilot/concepts/security-governance-and-network-settings/risks-and-mitigations) page, December 6, 2026.

**Run by us:** no. Commands and settings are copied from Anthropic's docs.

## Where does injected text get into a coding agent?

Injected text gets in through anything the agent reads that you didn't write. OWASP's [LLM01:2025](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) entry defines the indirect form: "Indirect prompt injections occur when an LLM accepts input from external sources, such as websites or files."

| Entry point | What carries the instructions | Documented by |
|---|---|---|
| Issues and pull request comments | Text an outsider can post on a public repository | Invariant Labs' [GitHub MCP research](https://invariantlabs.ai/blog/mcp-github-vulnerability), May 26, 2025 |
| Repository files | A README, code comment or docs page the agent opens | OWASP LLM01 ("websites or files") |
| Web pages and search results | A page the agent fetches | OpenAI: "Prompt injection can cause the agent to fetch and follow untrusted instructions." |
| MCP tool results | A ticket, message or document a tool returns | MCP Tools spec: clients SHOULD "Validate tool results before passing to LLM" |
| MCP tool descriptions | A server's own tool definitions | [Tool poisoning](/guides/tool-poisoning) |

Invariant's GitHub research is the clearest published demonstration. An attacker files an issue in a public repository. When the owner asks an agent connected to the GitHub MCP server to look at open issues, the agent follows the issue's instructions, pulls data from the owner's private repositories and posts it in a pull request on the public one.

Invariant ran the demo with Claude Desktop and Claude 4 Opus. It said the problem "is not specific to any particular agent or MCP client" and is "not a flaw in the GitHub MCP server code itself," but "a fundamental architectural issue that must be addressed at the agent system level."

## Why can't the agent just ignore injected instructions?

Your request and the untrusted text reach the model in the same context, and no documented method reliably tells them apart. OWASP says it is unclear whether fool-proof prevention exists, and vendors say the same about their own filters:

| Source | What it says |
|---|---|
| Anthropic, on Claude Code's safeguards | "no system is completely immune to all attacks" |
| Grok Build, on its classifier-based Auto-review mode | "Auto-review is not a security boundary" and "The classifier can make mistakes" |

So the practical goal is to cap what an injected instruction can do. OWASP's [LLM06:2025 Excessive Agency](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/) names three root causes: "excessive functionality," "excessive permissions" and "excessive autonomy." In a coding agent, those are tools and MCP servers the task doesn't need, read access to keys and broad tokens, and writes or network calls nobody reviews. The LLM01 entry's own mitigations include least privilege and "human-in-the-loop controls for privileged operations to prevent unauthorized actions."

## What do the main coding agents do by default?

Defaults differ, so check what your agent runs without asking. As of December 6, 2026, the vendors document these:

| Agent | What runs without asking | Sandbox and network |
|---|---|---|
| Claude Code | Interactive terminal and VS Code sessions begin in Auto mode, where a classifier reviews actions; Manual mode begins with read-only permissions and asks before edits or commands | Sandbox off by default; when on, outbound traffic goes through a proxy whose allowed domains start empty |
| Codex CLI and IDE extension | Asks before editing files outside the workspace or running commands that need network access | `workspace-write` sandbox with network off by default, enforced by OS mechanisms (`bwrap` plus `seccomp` on Linux) |
| Grok Build (formerly Cursor) | Three run modes: Auto-review, Allowlist and Run Everything | Sandboxed terminal commands get the workspace; network "Blocked by default"; paths such as `.git/hooks` protected |
| GitHub Copilot cloud agent | Starts only for users with write access to the repository | Internet access restricted by a firewall; pushes to a single branch |

Read the gaps as closely as the defaults. Anthropic's [sandboxing docs](https://code.claude.com/docs/en/sandboxing) say "The sandbox covers shell commands only," and local MCP servers and command hooks run "with your full access." GitHub's [firewall page](https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-the-firewall) says the firewall doesn't directly cover MCP servers apart from the built-in Playwright one, and "should not be considered a comprehensive security solution." OpenAI says Codex's network proxy doesn't filter web search, connector tool calls or MCP server connections. [How coding agents ask permission](/guides/coding-agent-permissions) compares the approval modes in full.

## How do I keep secrets out of an injected agent's reach?

List the secret files and variables yourself, because Claude Code ships no default list. This configuration from Anthropic's sandboxing docs blocks two credential paths and two tokens from sandboxed commands:

```json
{
  "sandbox": {
    "enabled": true,
    "credentials": {
      "files": [
        { "path": "~/.aws/credentials", "mode": "deny" },
        { "path": "~/.ssh", "mode": "deny" }
      ],
      "envVars": [
        { "name": "GITHUB_TOKEN", "mode": "deny" },
        { "name": "NPM_TOKEN", "mode": "deny" }
      ]
    }
  }
}
```

Anthropic is explicit: "There is no built-in credential deny list, so only the files and variables you list are restricted." Without entries, sandboxed commands can read most of the machine, "including credential files such as `~/.ssh` and `~/.aws/credentials`."

The `sandbox.credentials` setting affects sandboxed Bash commands only. Claude's Read tool follows permission rules instead, so add `Read` deny rules such as `Read(./.env)` or `Read(./secrets/**)`, per the [permissions docs](https://code.claude.com/docs/en/permissions). For MCP servers, the MCP project's [Local Server Security guide](https://modelcontextprotocol.io/docs/2026-07-28/tutorials/security/local-server-security) recommends giving each server its own narrowly scoped token through per-server config, not secrets exported in your shell profile.

## How do I run an agent on a repository I didn't write?

Strip the repository's own configuration first, because some of it runs before any prompt. Anthropic's permissions docs list what a repository supplies in a `claude -p` or Agent SDK run in a folder you never trusted, and the flags that turn it off:

| Repository content or flag | Effect, per Anthropic |
|---|---|
| Hooks, the `env` block and helpers such as `apiKeyHelper` in its settings files | Used in `claude -p` and SDK runs |
| Servers in `.mcp.json` | "Connected without asking, approved or not" in `claude -p` runs |
| `--setting-sources user` | Claude Code reads neither the project's settings files nor its `.mcp.json` |
| `--bare` | Skips the project's hooks, skills, custom commands, subagents and `.mcp.json` servers; its `env` block still applies |
| `--settings '{"disableAllHooks": true}'` | Turns hooks off for that run |
| `disabledMcpjsonServers` | Rejects a named `.mcp.json` server in every session type |

Strictly speaking, hooks and `.mcp.json` servers are repository code, not prompt injection. They belong on this list because they arrive from the same untrusted source. In interactive sessions, Claude Code shows a workspace trust dialog and asks before connecting `.mcp.json` servers, per its [MCP docs](https://code.claude.com/docs/en/mcp).

Anthropic's [security page](https://code.claude.com/docs/en/security) adds two isolation options: run the whole Claude Code process in its sandbox runtime or a dev container, and use VMs "to run scripts and make tool calls, especially when interacting with external web services."

## Where should a human still approve?

Keep a person on the steps where an injected instruction becomes hard to undo: network calls, pushes and merges. These are documented controls that put a human there:

| Control | Agent | Documented behavior |
|---|---|---|
| Human merge | GitHub Copilot cloud agent | Its draft pull requests "must be reviewed and merged by a human"; it "cannot approve or merge a pull request" |
| Workflow approval | GitHub Copilot cloud agent | Actions workflows don't run on its pull request until a user with write access approves them |
| Hidden-text filter | GitHub Copilot cloud agent | Filters hidden characters; text in an HTML comment "is not passed" to the agent |
| Network command prompts | Claude Code (Manual mode) | `curl` and `wget` prompt by default; add them to `permissions.deny` to block them |
| Per-call approval on a tool | Claude Code | An MCP tool with `_meta["anthropic/requiresUserInteraction"]` set to `true` prompts on every call, even in `auto` and `bypassPermissions` modes |

For a local agent, protected branches with required pull request reviews give you the same checkpoint as GitHub's human-merge rule. Narrow scope helps as much as prompts do. Invariant's mitigation for the GitHub case was to limit an agent to "only the repositories it needs to interact with," one repository per session. Apply the same thinking to tokens: an agent holding a token scoped to one repository can't read the others through it.

## What to read next

- [Tool poisoning: how a tool description can hijack an agent](/guides/tool-poisoning)
- [How coding agents ask permission: approval modes compared](/guides/coding-agent-permissions)
- [Claude Code MCP config: commands, scopes and managed settings](/guides/claude-code-mcp)
- Glossary: [prompt injection](/glossary/prompt-injection) and [least-privilege agents](/glossary/least-privilege-agents)

## Sources

1. [LLM01:2025 Prompt Injection, OWASP Gen AI Security Project](https://genai.owasp.org/llmrisk/llm01-prompt-injection/)
2. [LLM06:2025 Excessive Agency, OWASP Gen AI Security Project](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/)
3. [GitHub MCP Exploited: Accessing private repositories via MCP, Invariant Labs (2025-05-26)](https://invariantlabs.ai/blog/mcp-github-vulnerability)
4. [Security, Anthropic](https://code.claude.com/docs/en/security)
5. [Configure permissions, Anthropic](https://code.claude.com/docs/en/permissions)
6. [Configure the sandboxed Bash tool, Anthropic](https://code.claude.com/docs/en/sandboxing)
7. [Connect Claude Code to tools via MCP, Anthropic](https://code.claude.com/docs/en/mcp)
8. [Agent approvals & security, OpenAI](https://learn.chatgpt.com/docs/agent-approvals-security)
9. [Run modes, Grok Build docs](https://docs.grok.com/build/agents-window/agent/security/run-modes)
10. [Risks and mitigations for GitHub Copilot cloud agent, GitHub](https://docs.github.com/en/copilot/concepts/security-governance-and-network-settings/risks-and-mitigations)
11. [Customizing or disabling the firewall for GitHub Copilot, GitHub](https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-the-firewall)
12. [Tools (2026-07-28), Model Context Protocol](https://modelcontextprotocol.io/specification/2026-07-28/server/tools)
13. [Local Server Security (2026-07-28), Model Context Protocol](https://modelcontextprotocol.io/docs/2026-07-28/tutorials/security/local-server-security)

## Changelog

- 2026-12-06: First published.

## Cite this page

Agents for Devs. "Prompt injection against coding agents: attack paths and defenses." Published Dec 6, 2026. https://agentsfordevs.com/guides/prompt-injection-coding-agents

- Page: https://agentsfordevs.com/guides/prompt-injection-coding-agents
- Markdown: https://agentsfordevs.com/guides/prompt-injection-coding-agents.md
- Reuse: quote or summarize with a link to the page. Terms: https://agentsfordevs.com/reuse
