Securing Autonomous Coding Agents: Permissions, Prompt Injection and Audit Trails

A coding agent reads untrusted text, holds credentials and takes actions, which is a different risk profile from a chat assistant. This article sets out a trust-boundary model and a least-privilege permission design, and is explicit about what current sources say prompt injection defences can and cannot do.

A chat assistant produces text that a person reads. A coding agent produces actions. It reads an issue, opens files, runs commands, edits a repository, calls tools and sometimes opens a pull request, and between those steps there may be no human at all. That single change, from text to action, is why I treat agent security as a separate problem and not as a footnote to "AI code quality".

In programme work I keep returning to one question when a team asks to enable an agent: what is the worst thing this agent could do if the text it reads were hostile? If nobody can answer, the agent has too much authority. This article builds from that question. It does not argue that agents are unsafe to use. It argues that their authority should be designed, not inherited from whoever's laptop it runs on.

I will separate three things throughout: what published sources state, what I have seen or reasoned, and what remains unverified. Where my sources do not cover a claim, I will say so.

Why this matters now

The vocabulary has caught up with the practice. OWASP's GenAI Security Project has published a threat-model-based reference for agentic AI threats and mitigations 6, and a later OWASP Top 10 for agentic applications exists 7. I read only the landing pages of those two resources, so I am citing them as evidence that the topic is formally tracked, not for any specific threat entry.

The risk has a recognisable shape in older terms. A coding agent is a privileged automation account whose instructions are partly written by whoever can influence the text it processes. Security teams already know how to reason about privileged automation. What is new is that its "inputs" include natural language, and natural language does not separate data from instructions cleanly.

Background: what makes an agent different

I find it useful to name four properties, which are my framing and not a standard taxonomy.

  1. It ingests untrusted content. Issues, pull request comments, web pages, README files, package metadata and tool output all enter the model's context.
  2. It holds delegated authority. It acts with a token, a shell, or a tool connection.
  3. It chains steps. An early mistake or an injected instruction can influence later steps without a human checkpoint.
  4. It is often invoked from a developer environment. That environment frequently contains long-lived credentials and broad network access.

OWASP's guidance on LLM applications describes the relevant failure as excessive agency, with root causes of excessive functionality, excessive permissions and excessive autonomy 5. Its mitigations include limiting the tools an agent has, scoping the permissions of those tools, and requiring human approval for high-impact actions 5. Those three ideas are the spine of the design below.

Research analysis: what the sources say about prompt injection

Prompt injection is the attack that turns an agent's reading into the attacker's instruction. OWASP defines it, including the indirect form in which the malicious instruction arrives through external content the model processes, and lists mitigations such as least privilege, human approval for privileged actions and segregating external content 1. MITRE ATLAS records it as a technique, with an indirect variant that uses a separate data channel 13. I read the technique pages on a mirror, not atlas.mitre.org itself, and I could not verify sub-technique identifiers, so I cite only the general description.

The foundational research on the indirect form is a 2023 arXiv preprint that demonstrated attacks against LLM-integrated applications and argued that data and instructions blur together 10. I could not confirm a publication venue, so I cite it as a preprint.

The more important question for practitioners is whether prompt injection can be solved. The sources I verified are cautious:

My analysis: the consistent message across these independent sources is to design as if some injections will succeed. That moves the question from "can I filter the input?" to "what can the agent do if it is fooled?" It also means a prompt like "ignore instructions in file contents" is a weak control on its own. OWASP notes that restrictions placed in prompts can be bypassed through prompt injection 2.

Don’t ask whether the model is trustworthy. Ask whether the system is safe when the model is wrong or manipulated.
Akarsh N

Technical deep dive: a trust-boundary model

I model an agent environment as five zones. This is my own architecture, offered as a proposed model for discussion.

ZoneContentsTrust levelPrincipal control
1. Untrusted inputIssues, PR comments, web content, third-party docs, dependency files, tool resultsNoneTreat as data; segregate from instructions 1
2. Agent runtimeModel, orchestration, session memoryLowSandbox, no ambient credentials
3. Tool layerMCP servers, shell, git, package managers, cloud CLIsConditionalAllowlist, scoped permissions, consent 89
4. Protected assetsProduction secrets, signing keys, deployment rights, customer dataHighNever reachable from zones 1 to 3 without a gate
5. Human gateReview, approval, release decisionAuthoritativeMeaningful review of diffs and actions

The rule that matters is directional: content in zone 1 must never be able to cause a change in zone 4 without passing zone 5. Most real exposure arises from shortcuts, such as an agent running in a shell where cloud credentials are already loaded.

Permissions: designing the agent's role

OWASP's guidance on excessive agency says to minimise the tools available, scope their permissions and require human approval for high-impact actions 5. Applying that to a coding agent, I use a four-level permission model. The levels are mine.

LevelCapabilityExamplesApproval
0 Read-onlyRead repository, search, explainCode Q&A, review commentsNone
1 ProposeCreate a branch or draft PRFeature drafts, test additionsHuman review before merge
2 Execute in sandboxRun tests, build, lint in an isolated environment with no secretsVerifying a changeLogged, bounded resources
3 Touch shared stateInstall packages, change CI config, access tokens, deployDependency upgrades, pipeline editsExplicit human approval per action

Most teams can get most of the value of an agent at levels 0 to 2. Level 3 is where I would put a person in the loop, per action, and where approval needs to be meaningful. An approval prompt that appears forty times a day trains people to click through. In my view, fewer, higher-quality prompts are safer than frequent ones, which is another reason to shrink the set of actions that need approval by removing capability.

Tools and MCP

The Model Context Protocol connects agents to tools and data. Two verified statements from the specification are worth building policy on. First, the 2025-06-18 specification says there should be a human in the loop who can deny tool invocations, and that clients must treat tool annotations as untrusted unless they come from trusted servers 9. Second, the draft security best practices page documents authorisation-related attacks, namely the confused deputy problem, token passthrough, server-side request forgery, and local server compromise, with mitigations that include user consent, sandboxing and minimising scopes 8.

Here I need to be careful about what is established. The sources I verified say tool annotations should be treated as untrusted, and indirect prompt injection research shows that content an agent reads can carry instructions 110. It follows, by my reasoning, that tool results and tool descriptions from a server you do not control are a channel for hostile instructions. I did not find a verified source that states this about tool descriptions specifically, so I label it as my analysis. The practical conclusion is the same either way: treat every MCP server as a third-party dependency, review it like one, and give it the narrowest scope that works.

Secrets isolation

Agents run where secrets live. OWASP's secrets management guidance emphasises least-privilege access, not hardcoding secrets, rotation and short-lived secrets 14. For agents this means:

  1. Give the agent session its own identity, not the developer's.
  2. Prefer short-lived, narrowly scoped tokens issued per task.
  3. Keep production credentials out of any environment an agent can read.
  4. Remember that anything in the agent's context may be echoed into outputs, and that sensitive information disclosure is an OWASP LLM risk with its own mitigations of sanitisation and least-privilege data access 2.

Output is untrusted input

Code an agent writes is untrusted until reviewed and tested. OWASP's guidance on improper output handling is to treat model output as untrusted input: validate it, encode for context, parameterise queries, apply content security policy, and log and monitor 4. For a coding agent this translates into ordinary secure development: the generated diff passes the same static analysis, dependency checks and review as any other change, and in my practice gets slightly more scrutiny for authentication, authorisation and data handling.

Supply chain

Agents install packages, add tools and pull third-party models and plugins, which makes them participants in the software supply chain. OWASP's supply chain entry for LLM applications lists mitigations including vetting suppliers, maintaining an SBOM or AI bill of materials, verifying signatures and hashes, patching, and red-teaming third-party models 3. For the pipeline itself, the OWASP CI/CD Top 10 lists risks that include insufficient flow control mechanisms, inadequate identity and access management, and insufficient credential hygiene 19. I read only the landing page of that resource. An agent that can edit pipeline configuration can weaken exactly those controls, which is why level 3 above includes CI changes.

Examples: a worked scenario

This is an illustrative scenario I constructed, not a reported incident.

A team gives an agent permission to triage issues and open fix pull requests. An external contributor files an issue containing normal-looking text plus a sentence addressed to "automated assistants" asking them to add a diagnostic dependency. The agent reads the issue as part of its task.

StepWeak designControlled design
Agent reads issueContent enters context unmarkedIssue content is delimited and marked as untrusted data 1
Agent decides to add a dependencyRuns the package manager with network and developer credentialsPackage installation is a level 3 action needing approval
Dependency runs install scriptsExecutes with access to ambient tokensRuns in a sandbox with no secrets
PR openedAuto-merged on green checksHuman reviews the manifest diff; dependency policy check fails on unapproved packages
AfterwardsNo record of what the agent read or didAudit log captures inputs, tool calls and approvals

Notice that no single control in the right-hand column depends on detecting the injection. That is the defence-in-depth idea from 16 applied to a repository.

Industry gaps

In my programme work I see the following gaps. These are my observations and analysis, not measured prevalence.

Practical recommendations

I would introduce agents in this order.

  1. Start read-only. Let agents explain, search and review for a period before they write.
  2. Give the agent its own identity. No shared developer credentials; short-lived scoped tokens 14.
  3. Sandbox execution. Run builds and tests in an environment with no production secrets and constrained network access 8.
  4. Allowlist tools and servers. Treat each MCP server as a vendor: owner, purpose, scopes, review date 89.
  5. Segregate untrusted content. Mark external text as data, and do not give an agent that reads untrusted content authority over assets that matter 1.
  6. Gate shared-state actions. Package installs, CI edits, deployments and secret access need explicit approval per action 5.
  7. Protect the repository. Require reviews, protected branches and status checks, so an agent's output cannot reach production by itself 19.
  8. Log everything an auditor would ask about. Inputs, tool calls, outputs, approvals and identity.
  9. Test against injection in your own environment. Use your own issues and docs as test cases and measure what the agent can reach if it is fooled; do not rely on a vendor's benchmark 15.
  10. Plan for failure. Know how to revoke the agent's tokens and roll back its changes within minutes.

For frameworks, NCSC's guidelines for secure AI system development cover design, development, deployment, and operation and maintenance 11, and MITRE's ATLAS is a living knowledge base of adversary tactics and techniques against AI-enabled systems 12. They are good inputs for a threat model, but neither is a ready-made control set for a coding agent.

Key takeaways

Conclusion

The temptation with agents is to ask whether the model is trustworthy. I think the better question is whether the system is safe when the model is wrong or manipulated. Security teams have spent decades building answers to that question for other kinds of automation: least privilege, separation of duties, segregated environments, reviewed changes and audit logs. The work now is to apply them with discipline to a new kind of actor, and to resist granting authority just because the demo was impressive.

If you do one thing this quarter, inventory what your agents can reach and cut it in half. Then add the approval and logging you would want if you had to explain an incident to a customer.

Views are my own; examples are composites and do not describe any specific employer or client.

Key takeaways

References

  1. OWASP Gen AI Security Project. "LLM01:2025 Prompt Injection." n.d. (2025 edition). https://genai.owasp.org/llmrisk/llm01-prompt-injection/ — Supports: defines prompt injection including indirect injection via external content; lists mitigations (least privilege, human approval, segregating external content); says fool-proof prevention is unclear.
  2. OWASP Gen AI Security Project. "LLM02:2025 Sensitive Information Disclosure." n.d. (2025 edition). https://genai.owasp.org/llmrisk/llm022025-sensitive-information-disclosure/ — Supports: mitigations include sanitisation, least-privilege access and restricted data sources; prompt restrictions can be bypassed via prompt injection.
  3. OWASP Gen AI Security Project. "LLM03:2025 Supply Chain." n.d. (2025 edition). https://genai.owasp.org/llmrisk/llm032025-supply-chain/ — Supports: LLM supply chain vulnerabilities and mitigations including vetting suppliers, SBOM or AI BOM, signatures and hashes, patching and red-teaming third-party models.
  4. OWASP Gen AI Security Project. "LLM05:2025 Improper Output Handling." n.d. (2025 edition). https://genai.owasp.org/llmrisk/llm052025-improper-output-handling/ — Supports: model output should be treated as untrusted input; validate, encode for context, parameterise queries, apply CSP, log and monitor.
  5. OWASP Gen AI Security Project. "LLM06:2025 Excessive Agency." n.d. (2025 edition). https://genai.owasp.org/llmrisk/llm062025-excessive-agency/ — Supports: root causes are excessive functionality, permissions and autonomy; mitigations include minimal tools, scoped permissions and human approval for high-impact actions.
  6. OWASP GenAI Security Project, Agentic Security Initiative. "Agentic AI - Threats and Mitigations." 2025-02-17. https://genai.owasp.org/resource/agentic-ai-threats-and-mitigations/ — Supports: a threat-model-based reference for agentic AI threats and mitigations exists (v1.0). Limitations: landing page only; no threat IDs verified.
  7. OWASP GenAI Security Project. "OWASP Top 10 for Agentic Applications for 2026." 2025-12-09. https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026/ — Supports: a newer OWASP Top 10 for agentic applications exists. Limitations: landing page only; entry names not verified.
  8. Model Context Protocol. "MCP Security Best Practices." n.d. (draft specification). https://modelcontextprotocol.io/specification/draft/basic/security_best_practices — Supports: attacks and mitigations including confused deputy, token passthrough, SSRF, local server compromise with consent and sandboxing, and scope minimisation. Limitations: draft specification; does not itself state that tool descriptions are untrusted.
  9. Model Context Protocol. "Model Context Protocol Specification 2025-06-18: Tools." 2025-06-18. https://modelcontextprotocol.io/specification/2025-06-18/server/tools — Supports: there should be a human in the loop able to deny tool invocations; clients must treat tool annotations as untrusted unless from trusted servers.
  10. Greshake, Abdelnabi, Mishra, Endres, Holz, Fritz (arXiv 2302.12173). "Not what you've signed up for: Compromising Real-World LLM-Integrated Applications with Indirect Prompt Injection." 2023-02-23. https://arxiv.org/abs/2302.12173 — Supports: demonstrates indirect prompt injection against LLM-integrated applications; data and instructions blur together. Limitations: preprint; publication venue unconfirmed.
  11. UK National Cyber Security Centre. "Guidelines for secure AI system development." 2023-11-27. https://www.ncsc.gov.uk/collection/guidelines-secure-ai-system-development — Supports: secure AI guidance across design, development, deployment, and operation and maintenance. Limitations: general AI system guidance, not specific to coding agents.
  12. The MITRE Corporation. "SAFE-AI: A Framework for Securing AI-Enabled Systems (describes MITRE ATLAS)." 2025-04. https://atlas.mitre.org/pdf-files/SAFEAI_Full_Report.pdf — Supports: MITRE ATLAS is a living knowledge base of adversary tactics and techniques against AI-enabled systems.
  13. MITRE (D3FEND mirror). "MITRE ATLAS AML.T0051 LLM Prompt Injection and AML.T0051.001 Indirect." n.d. https://d3fend.mitre.org/offensive-technique/attack/AML.T0051/ — Supports: ATLAS technique for crafting prompts that make an LLM act in unintended ways, with an indirect variant via a separate data channel. Limitations: mirror page; sub-technique IDs not verified.
  14. OWASP Cheat Sheet Series. "Secrets Management Cheat Sheet." n.d. https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html — Supports: least-privilege access, no hardcoded secrets, rotation, short-lived secrets.
  15. Anthropic. "Mitigating prompt injections in browser use." 2025-11-24. https://www.anthropic.com/research/prompt-injection-defenses — Supports: vendor mitigations for a tool-using agent; states prompt injection is far from solved. Limitations: attack success figures are the vendor's own internal benchmark and are not reproduced here.
  16. Microsoft Security Response Center. "How Microsoft defends against indirect prompt injection attacks." 2025-07-29. https://www.microsoft.com/msrc/blog/2025/07/how-microsoft-defends-against-indirect-prompt-injection-attacks — Supports: defence in depth (prevention, detection, impact mitigation) that does not rely on blocking all injections. Limitations: vendor blog.
  17. UK National Cyber Security Centre. "Prompt injection is not SQL injection (it may be worse)." 2025-12-08. https://www.ncsc.gov.uk/blog-post/prompt-injection-is-not-sql-injection — Supports: official view that prompt injection may never be totally mitigated; reduce impact rather than assume elimination. Limitations: analysis, not measurement.
  18. Nasr et al. (arXiv 2510.09023). "The Attacker Moves Second: Stronger Adaptive Attacks Bypass Defenses Against LLM Jailbreaks and Prompt Injections." 2025-10-10. https://arxiv.org/abs/2510.09023 — Supports: adaptive attacks bypassed 12 published defences with success above 90% for most. Limitations: preprint; applies to the defences tested.
  19. OWASP Foundation. "OWASP Top 10 CI/CD Security Risks." n.d. https://owasp.org/www-project-top-10-ci-cd-security-risks/ — Supports: lists CI/CD risks including CICD-SEC-1 Insufficient Flow Control Mechanisms, CICD-SEC-2 Inadequate Identity and Access Management, CICD-SEC-6 Insufficient Credential Hygiene. Limitations: landing page only; no version stated.