Treat repository files as untrusted input and keep agent execution separate from repository-controlled instructions. Use a allowlist of permitted command templates, run tools in a sandbox, and require human approval before any command that changes files, secrets or network state. The phrase repository context is untrusted captures the core control boundary.
How should teams prevent repository instructions from becoming execution authority?
The core mistake is letting the repository become a control plane. Files in the repo, including instruction files, must be treated as untrusted input, while execution authority stays with the agent runtime, not with whatever the repository asks it to do. That means you constrain what can run, where it can run, and when a human must approve it.
A practical boundary is to separate instruction parsing from command execution. The agent can read repo context, but it should only be allowed to invoke a small set of preapproved command templates, with arguments validated against policy before execution. For code-changing, secret-accessing, or network-reaching actions, the safe default is to stop and request approval rather than infer intent from repository text.
This is the same control logic behind sandboxed agent execution: the repository may suggest work, but it should never expand the agent’s authority. NHIMG’s AI Agent Sandboxing and Code Execution Guide covers how to isolate agent-run code with runtime, filesystem, and egress controls so instruction files cannot silently widen execution scope.
Where do these failures usually happen?
The common failure mode is instruction injection through files that developers assume are harmless, such as README content, agent instruction files, or repo-local prompts. If the agent is allowed to interpret those files as executable policy, a poisoned instruction can redirect tooling, exfiltrate secrets, or trigger unsafe shell commands without any change to the agent binary itself.
Another failure mode is overly broad tool access. Once an agent can spawn shells, write files, or access tokens, repository instructions can steer it into actions that look routine but have material side effects. A good example is the sort of hidden-command execution problem shown in NHIMG’s Gemini CLI prompt injection flaw 2025, where poisoned repository content was enough to make a coding tool execute hidden commands and expose secrets.
Teams should also watch for implicit trust in local automation. If an agent can write to the working tree, access environment variables, or reach the internet without checks, a repo instruction file becomes a convenient staging point for abuse rather than a harmless hint.
What control pattern works best in practice?
Use a layered pattern: parse instructions, classify them, and execute only through a policy gate. A repository may request a build, test, or analysis action, but the runtime should translate that request into a fixed command template rather than free-form shell execution. Sensitive actions need stronger controls, such as human approval, read-only default mode, secret redaction, and explicit egress restrictions.
For teams building or operating coding agents, this is not just a prompt-design issue. It is an execution-governance issue that benefits from a sandbox-first design. NHIMG’s AI Coding Agents Security Guide is useful for separating agent instruction handling from secrets, supply chain risk, and sandbox boundaries in IDE, terminal, and CI/CD workflows.
Where the repository can influence tool choice, the approval boundary should sit before the tool runs, not after. That is the difference between a controlled automation and an agent that can be driven by untrusted text into changing files, touching secrets, or reaching external services.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Agentic AI Top 10 and OWASP API Security Top 10 address the attack and risk surface, while NIST SP 800-53 Rev 5 sets the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Agentic AI Top 10 | ASI02 — Tool Misuse | Repository instructions can steer agents into unsafe tool actions. |
| ASI03 — Identity & Privilege Abuse | Repo-driven execution becomes dangerous when agents can act with excessive authority. | |
| ASI05 — Unexpected Code Execution | The question is about preventing repository text from becoming executable agent code. | |
| Recommendation — Restrict tool invocation to approved templates and block free-form command generation. Scope agent privileges narrowly and require approval for state-changing actions. Run agent execution in a sandbox and validate all instruction-derived actions before launch. | ||
| OWASP API Security Top 10 | API8 — Security Misconfiguration | Unsafe defaults in agent tool access and execution policy create exploitable misconfiguration. |
| Recommendation — Harden execution settings so repository content cannot expand runtime permissions. | ||
| NIST SP 800-53 Rev 5 | AC-6 — Least Privilege | Agents need only the minimum authority needed to process repo instructions safely. |
| CM-7 — Least Functionality | Allowlisting command templates directly reflects limiting agent functionality. | |
| IA-5 — Authenticator Management | Repository-driven actions often become secret-exposure events if credential handling is weak. | |
| Recommendation — Limit agent permissions to the minimum required for the approved task. Disable unnecessary tools and execution paths that repo content could abuse. Protect and rotate credentials that the agent can reach during execution. | ||
Practitioner Guidance
What to prioritise: Start by reducing the agent’s ambient authority. If the agent can execute shell commands, mutate files, or reach secrets by default, repository instructions will always be a plausible abuse path even if the prompt looks well designed.
What to verify: Check that approval is required for any command template that can change state, access credentials, or make outbound connections. Also verify that the agent cannot bypass policy by composing commands dynamically from repository text.
Common mistake: Teams often harden the prompt format but leave the execution layer wide open. That only makes the unsafe path more polished, not safer.
Practitioner takeaway: The safest design is to let repositories describe work, not authorise it; execution should remain policy-bound, sandboxed, and reviewable even when the instruction source is trusted by the development workflow.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org