Prompt Injection in Coding Agents
Last updated: 2026-07-173 min read
Prompt injection is a trust-boundary attack, not a synonym for every wrong model action. Untrusted content can alter an agent’s behavior. Data disclosure or tool abuse additionally requires reachable capabilities and failed controls. Layered controls can reduce likelihood or impact; none makes the attack class disappear.
Contents
Start with the attack definition
The NIST definition centers on untrusted input being combined with a higher-trust prompt. In a coding workflow, that input can be a repository file, issue, retrieved page, dependency text, or tool response. Checked 17 July 2026. This definition supports a threat model; it does not prove that a particular artifact is malicious or that an observed mistake was an attack.
OWASP LLM01:2025 distinguishes direct and indirect injection and lists possible consequences. Whether an injection can read a secret, call a shell, alter a branch, or send data depends on the capabilities the surrounding agent actually has. Prompt injection, tool abuse, data exfiltration, and ordinary model error are therefore related but distinct findings.
Design for constrained capability, then test it
Treat model output as an untrusted request to a separate enforcement layer. Minimize credentials and tool scope, isolate execution, validate arguments and outputs, require approval at consequential boundaries, constrain egress and sensitive data, and retain traces. These are layered risk treatments, not a security guarantee. A sandbox limits the environment; it does not make the model ignore adversarial text. A local model changes a hosting path; it does not remove network, filesystem, extension, log, or tool channels. One concrete shape for that enforcement layer is a read-only tool surface whose refusals are written down in advance.
Keep threat, control, evidence, and residual risk separate
| Untrusted input | Altered model behavior | Tool abuse path | Data-disclosure path | Ordinary model error | |
|---|---|---|---|---|---|
| QuestionWhat is being evaluated? | Can an attacker influence content the agent consumes?Threat decomposition · 2026-07-17A review question, not a finding. | Did the content change the model's instruction following?Threat decomposition · 2026-07-17A review question, not a finding. | Could altered behavior invoke a consequential tool?Threat decomposition · 2026-07-17A review question, not a finding. | Could the agent read and transmit sensitive data?Threat decomposition · 2026-07-17A review question, not a finding. | Was there adversarial input, or a non-adversarial failure?Threat decomposition · 2026-07-17A review question, not a finding. |
| ControlWhat changes the reachable path? | Provenance, allowlists, content boundaries, and retrieval policyLayered-control exampleSelect and test controls for the actual architecture. | Prompt structure, model safeguards, input/output validation, and adversarial testingLayered-control exampleSelect and test controls for the actual architecture. | Least privilege, capability scoping, argument validation, isolation, and approvalLayered-control exampleSelect and test controls for the actual architecture. | Data classification, secret isolation, egress controls, and redactionLayered-control exampleSelect and test controls for the actual architecture. | Specifications, tests, review, monitoring, and incident analysisLayered-control exampleSelect and test controls for the actual architecture. |
| EvidenceWhat can be observed and retained? | The exact retrieved content and its originObservable artifactEvidence scope is limited to the recorded configuration and event. | Captured input, output, model/configuration, and test resultObservable artifactEvidence scope is limited to the recorded configuration and event. | Granted tools, denied calls, approvals, and execution logsObservable artifactEvidence scope is limited to the recorded configuration and event. | Accessible data paths, network policy, and observed transfersObservable artifactEvidence scope is limited to the recorded configuration and event. | Input origin, trace, changed files, checks, and observed effectObservable artifactEvidence scope is limited to the recorded configuration and event. |
| Residual riskWhat remains unresolved? | Allowed content can still contain adversarial instructionsResidual-risk boundary · 2026-07-17No elimination or security guarantee is inferred. | Behavior remains probabilistic and fixture coverage is finiteResidual-risk boundary · 2026-07-17No elimination or security guarantee is inferred. | A permitted tool may still be misused within its scopeResidual-risk boundary · 2026-07-17No elimination or security guarantee is inferred. | Unknown channels, logs, or configuration drift may remainResidual-risk boundary · 2026-07-17No elimination or security guarantee is inferred. | Similar symptoms do not establish the same causeResidual-risk boundary · 2026-07-17No elimination or security guarantee is inferred. |
Evidence must name its test boundary
A useful test records the untrusted fixture, model and configuration, granted capabilities, attempted action, enforcement result, and residual-risk decision. Passing one fixture shows what those controls did in that configuration. It does not cover unseen inputs or later drift. Pair adversarial tests with ordinary correctness checks so a security label does not hide a normal model or software defect. See the broader verification boundary.
Where Reality Graph fits
Reality Graph can bind a task to allowed files, selected checks, observed results, changed files, and an operator decision. That can make one control reviewable. It cannot identify every hostile input, prevent the model from following one, or prove that a repository, tool, or deployment is secure.
A bounded record can show
- Which content, identities, data, tools, and network paths one run could reach
- Which checks and approvals were required and what they observed
- Known exceptions, failed controls, and residual-risk decisions
It cannot establish
- That filtering, sandboxing, local inference, approval, or verification eliminates prompt injection
- That a hypothetical path or suspicious output proves attack, exfiltration, or tool abuse
- That future models, inputs, tools, configurations, or integrations are secure
FAQ
- What is prompt injection in a coding-agent workflow?
- NIST defines prompt injection as an attack that exploits the concatenation of untrusted input with a prompt constructed by a higher-trust party. For a coding agent, untrusted input can include repository files, issues, web content, or tool output. An altered model response is the threat event; tool abuse or data disclosure requires additional exposed capabilities and failed controls.
- Is every wrong agent action prompt injection?
- No. Prompt injection requires adversarially influenced input. An ordinary model error, ambiguous instruction, stale context, software defect, or operator mistake can produce a similar bad action without an attacker. Preserve the input, model and tool trace, approvals, and observed effect before assigning a cause.
- Does sandboxing eliminate prompt injection?
- No. A sandbox can constrain reachable resources and reduce impact, but the model can still follow adversarial instructions inside it. Least privilege, isolated execution, approval gates, input provenance, output validation, and monitoring are layers; their effectiveness depends on configuration and testing.
- Does a local model prevent data exfiltration?
- Not by itself. Local inference changes one data path. An agent may still have network access, secrets, files, tools, logs, extensions, or other channels. The relevant evidence is the actual capability graph and observed controls, not the deployment label.
- What evidence should a control review retain?
- Retain the untrusted-input boundary, granted identities and tools, network and filesystem policy, approval points, control configuration, test case, observed action, blocked action, exceptions, and review date. That can show what one control did under one test; it is not proof that prompt injection is eliminated.
Keep reading
Sources
- OWASP GenAI Security Project - LLM01:2025 Prompt Injection, impacts and mitigations (checked 2026-07-17)
- NIST AI 100-2e2025 - adversarial ML taxonomy, attacks and mitigation limits (published 2025-03-24; checked 2026-07-17)
- NIST CSRC glossary - prompt-injection definition sourced to NIST AI 100-2e2025 (checked 2026-07-17)