Git has a trust model. Commits are signed or unsigned, branches are protected or open, tokens are scoped. An AGENTS.md file has none of that. It is read as plain text at the start of a session and handed to the model with the same weight as the operator’s own system prompt, which is why AGENTS.md prompt injection is worth testing as its own attack surface rather than as a footnote under indirect prompt injection. The file was never designed to be trusted. It is simply believed.
Most published material on this stops at the general principle or walks through a single proof of concept. What follows is a test sequence: where the files are loaded from, what to plant, how to judge whether anything actually happened, and what containment survives after the model has been fooled.
Why an AGENTS.md File Is Read as Orders, Not Notes
AGENTS.md is an open convention for repository-level agent instructions: build commands, test commands, style rules, things a human contributor would find in a CONTRIBUTING file. Several coding agents load it automatically at session start, including OpenAI Codex and Google Jules, with adoption spreading across other tools. Check your agent’s current documentation, because the list changes.
There is no signature on the file. No author check, no provenance, no trust boundary between a maintainer’s policy and a stranger’s fork. The model cannot separate the instructions it was given from the text it reads, so a cloned repository’s guidance file arrives looking exactly like policy. That is the whole vulnerability, and it is the same root cause described in the vulnerability that defines LLM security.
The sibling files share the weakness exactly. CLAUDE.md for Claude Code, .cursor/rules for Cursor, .github/copilot-instructions.md for Copilot. Then the unofficial ones: README build notes, Makefile comments, issue bodies, pull request descriptions, docstrings in a vendored dependency. Anything the agent ingests while working is a candidate. Instruction files are just the honest version, because they are read every time without being asked for.
In published frameworks this is LLM01 prompt injection combined with excessive agency in the OWASP Top 10 for LLM Applications, indirect prompt injection in MITRE ATLAS, and a secure design failure against the NCSC Guidelines for Secure AI System Development, which ask you to consider adversarial inputs to the system rather than treating the model as a trusted component.
The Attack Chain From Cloned Repo to Privileged Tool Call
Delivery. A fork, a contributor pull request, a vendored dependency, a sample project a developer clones to reproduce a reported bug. None of these require a compromise of the main repository. The attacker only needs text that the agent will read on the developer’s machine or in CI.
Concealment. HTML comments do not render in GitHub’s markdown view but survive intact in the raw file the agent reads. So do collapsed <details> blocks, zero-width characters, white-on-white styling in rendered docs, and instructions parked inside a link title. A reviewer skims the diff and sees build notes. The agent sees the comment.
Redirection. The payload rarely tries to defeat safety training, and testers who only probe for refusals miss it. It asks for something plausible: a setup command before the tests will pass, a dependency pulled from an unusual registry, a config file read from outside the workspace because “the local override lives in the parent directory”. Framed as a build requirement, it reads like work rather than an attack.
Consequence. The agent already holds credentials. A .env in the workspace, ~/.aws/credentials, an SSH private key, a GITHUB_TOKEN in the environment. The repository author cannot touch any of those, but the agent can, and the agent will act on text the author wrote. That is a confused deputy wearing a developer’s badge, and it is the pattern worth naming in your report.
Map Permissions, Inputs and Data Flows Before You Attack
List every path the agent auto-loads. Repository root, nested per-directory instruction files, and any global user-level config in the home directory that applies across projects. Nested files are the most commonly missed test case by a wide margin. A tester who plants one payload in the root, watches the agent ignore it, and signs the engagement off has tested one file while a second one three directories down, inside the package the agent was told to refactor, is read with full force the moment work reaches that folder.
Then inventory the tool surface. Shell execution, file write, network egress, git push, package install, connected MCP servers. For each one, record whether it runs behind an approval prompt or silently. If MCP is in play, the connected servers widen the surface considerably, and testing those servers directly belongs in the same engagement.
Record what the process can reach: secrets in environment variables, mounted credential files, CI variables, internal endpoints reachable from the runner. Finally, decide the consequence you are testing for before the first payload is written. “Exfiltration of a CI secret to an external host”is a finding with a definition. “The agent behaved oddly”is not.
A Test Sequence for AGENTS.md Prompt Injection
Canary first. Plant a harmless instruction inside an HTML comment in AGENTS.md telling the agent to fetch a URL you control with the hostname appended as a path segment. The finding is the entry in your listener log, with its timestamp and source address. Not the agent’s reply. An agent that says it fetched the URL and did not has proved nothing except that models narrate.
Instruction-bypass variants. Run a direct override of the operator’s stated rules, then the same instruction hidden rather than plain, then a precedence conflict where a nested file contradicts the root. Precedence is poorly specified across tools and worth documenting per agent. Which file wins when they disagree is often not what the vendor’s documentation implies.
Tool abuse and the confused deputy test. Can repository text cause the agent to use the developer’s credentials for an action the repository author should never be able to trigger? Reading a file outside the workspace. Running an install from a registry that is not the configured one. Pushing a branch. Opening an outbound connection during a build step.
Excessive agency and persistence. Try getting the agent to write or amend its own instruction file, add a git hook, or append a line to a CI workflow. Then start a fresh session and see whether the instruction carried. Persistence turns a single injection into a standing one.
Supply chain variation. Move the payload out of the repository under review entirely. Put it in a dependency’s README inside node_modules, or in the body of a pull request the agent is asked to triage. The scenario worth modelling: a contributor PR adds a nested instruction file next to an innocuous test fixture, and the triage agent runs in CI with a repository-scoped token that can push branches and read Actions secrets. Nobody reviewed the file, because the agent reviewed the PR.
Judge the Finding by What the Agent Did
A forbidden sentence in a transcript is not a finding. A logged callback is. So is a file written outside the workspace, a pushed commit, an installed package, a process that opened a socket it had no business opening. Keep tool call logs, HTTP listener entries, shell history, diffs, timestamps, the exact bytes of the planted file, and the agent version plus its approval settings. Settings matter because the same payload against the same model behaves differently with auto-approve enabled, which is the same discipline set out in this methodology for taking AI findings from scope to proof.
Non-determinism changes how you write it up. Run each payload a fixed number of times, ten is a reasonable floor, and report the hit rate honestly. A single screenshot of a success is weak evidence and a competent engineering lead will say so. Attempts, successes and conditions are stronger. And one success in eight is not a weak finding when the agent is invoked on every pull request all day.
Rate severity by blast radius, not by the cleverness of the payload. An elegant injection against an agent with read-only access to a sandbox is a low. A clumsy one against a CI agent holding a token that can push to main is not.
Containment That Survives a Fooled Model
Assume the injection lands. Every mitigation that depends on the model correctly identifying hostile text will fail some percentage of the time, and you cannot know the percentage in advance. Scope permissions so the worst case is recoverable: no plaintext secrets in the agent’s environment, short-lived tokens, an egress allowlist on the runner, and workspace isolation that makes ~/.ssh unreachable from the process. Permission scoping is the only control in this list that does not care whether the model was convinced. The wider discipline is covered in securing AI agents and their tool use. For a structured method of mapping those permissions before you scope an engagement, see the article on testing an AI agent end to end.
Treat instruction files as code. Review them in diffs, put CODEOWNERS on AGENTS.md, CLAUDE.md, .cursor/rules and .github/copilot-instructions.md, and raise a flag when one of them appears in a fork, a dependency or a first-time contributor’s branch. A new nested instruction file in a PR deserves the same attention as a new postinstall script.
Put approval gates where they earn their place: shell execution, package install, git push, outbound network calls. A blanket prompt on every action trains the developer to click through, which is worse than no prompt because it manufactures a record of consent.
And the line in the system prompt telling the model to distrust repository text? Test it rather than trust it. Teams routinely treat that sentence as the fix. The payload that beats it is usually not an aggressive override but a polite one phrased as a build requirement the agent needs in order to finish the task it was given. Helpfulness wins. Filtering and instruction hierarchy are partial mitigations worth having, and they are not a boundary.
Writing It Up So the Team Can Act, Then Retesting
Ship a minimal reproduction repository with the exact agent configuration: version, model, approval mode, enabled tools, MCP servers connected. Without that, the first engineer who cannot reproduce it will close the ticket.
Describe probabilistic results plainly. Attempts, successes, the conditions under which it fired, and what changed between runs. Then retest after each mitigation and record which variants now fail and which still land. Partial fixes are common here and they are still progress, provided the report says which is which. The adjacent paths worth covering in the same engagement are set out in this list of AI coding agent attack paths.
One question for any product sold as an agent security scanner: where does its verdict come from? A model asserting that the output looks safe, or a listener that logged an outbound request the agent should never have made. A great deal of what is claimed in this space is marketing, and the questions that sort the tools apply here as much as anywhere. If the evidence is a model’s opinion of a model, it is not evidence.
The Short Version
Agent instruction files are context, not configuration, so a stranger’s fork carries the same authority as your own policy. Test nested files, not just the root. Judge findings by logged actions rather than transcript text, run each payload repeatedly and report the hit rate. Scope permissions so a successful AGENTS.md prompt injection is survivable, because every other control assumes the model got it right.
Frequently Asked Questions
What is AGENTS.md and which coding agents read it automatically?
AGENTS.md is an open convention for a repository-level instruction file that tells a coding agent how to build, test and work within the project. Several agents load it at session start, including OpenAI Codex and Google Jules, and other tools use their own equivalents such as CLAUDE.md, .cursor/rules and .github/copilot-instructions.md. Support shifts quickly, so confirm against your agent’s current documentation rather than assuming.
Can AGENTS.md prompt injection work if nobody ever opens the file?
Yes, and that is the point. The agent reads the file automatically whether or not a human does, and payloads hidden in HTML comments or collapsed blocks do not appear in the rendered markdown a reviewer skims. A file that no person has read can still steer every action the agent takes in that session.
Does telling the agent to ignore instructions found in repository files stop the attack?
It reduces the success rate and does not close the hole. Instruction hierarchy is a preference inside the model, not an enforced boundary, and payloads phrased as build requirements the agent needs in order to complete its task frequently win. Measure it: run the same payload set with and without the line and compare hit rates.
How do I test AGENTS.md prompt injection safely without harming a live repository?
Use a disposable fork or a purpose-built reproduction repository, a throwaway token scoped to it, and a dedicated workspace with no real credentials mounted. Point canaries at a listener you control and keep payloads to information disclosure of planted dummy secrets rather than real ones. Get the scope and the consequence you are testing for agreed in writing first.
Is it safe to let an AI coding agent work inside a cloned open-source project?
It is safe in proportion to what the agent can reach. Running inside a container with no plaintext secrets, an egress allowlist and approval gates on shell and push is a reasonable risk. Running on a developer laptop with auto-approve, an SSH key and a long-lived token present is handing a stranger’s text a privileged session.
