ASI05 Unexpected Code Execution is an OWASP Top 10 for Agentic Applications risk in which an AI agent generates or runs code or commands that the designer did not intend, often after prompt injection or poisoned input. Defenders run agent code in isolated sandboxes with minimal privileges and restricted network access, and require approval for high-impact commands.
What ASI05 Means in Practice
ASI05 describes a failure of control at the code boundary, where an agent produces or executes code that exceeds the designer's intent. The danger is not simply that code runs, but that the system turns language, context, or tool output into executable action without a reliable policy checkpoint.
In agentic systems, that boundary is easy to blur because the same model may read instructions, generate commands, call tools, and interpret results. When the agent is influenced by prompt injection or poisoned input, it may treat attacker-controlled text as legitimate work rather than hostile instruction.
This is why ASI05 sits at the intersection of application logic, execution control, and trust in model output. A safe design treats code generation as untrusted until it passes explicit validation, containment, and approval rules.
Why Unexpected Code Execution Is Dangerous
Unexpected code execution is dangerous because it can convert a harmless-looking prompt into shell commands, scripts, API calls, or other high-impact actions. If the agent has access to files, tokens, internal services, or deployment tooling, the blast radius can expand well beyond the original user request.
The core failure is over-trust in generated output. Once a model is allowed to create executable instructions, even a small prompt-injection success can become remote code execution, data access, or destructive change depending on the privileges behind the agent.
Strong containment matters because execution abuse often follows the same pattern: input manipulation, unintended command generation, tool invocation, and then secondary compromise through whatever the agent can reach. The safest assumption is that any text the agent consumes may be adversarial unless proven otherwise.
Common Failure Patterns and Control Boundaries
ASI05 usually appears when developers connect a model to interpreters, scripts, notebooks, CI pipelines, or admin tools without enough separation between reasoning and execution. It is especially risky when the agent can chain tool output into another command, or when approval is only applied to a narrow subset of actions.
One recurring boundary failure is letting the model decide when code is safe to run. Another is giving the agent broad filesystem, network, or credential access, which turns an execution bug into a larger compromise path.
In well-designed systems, generated code stays in a constrained sandbox, commands are allowlisted, and high-impact actions require explicit human review. That separation reduces the chance that a poisoned prompt becomes an unauthorised operational change.
How Defenders Reduce the Blast Radius
Defenders reduce ASI05 risk by keeping execution environments isolated, minimal, and short-lived. The main objective is to make code generation possible without making arbitrary execution broadly powerful.
That usually means restricting outbound network access, removing unnecessary credentials, limiting filesystem reach, and separating the agent's reasoning loop from the environment that can actually change state. Approval gates are especially important for actions that could alter infrastructure, exfiltrate data, or invoke administrative functions.
For practical guidance on this control stack, see Agentic AI Risk Assessment Template for pre-deployment approval and reassessment, and AI Agent Sandboxing and Code Execution Guide for sandboxing, egress control, and execution isolation.
Risk and Threat Considerations
ASI05 matters because code execution failures turn a language-level compromise into an operational one. A malicious prompt or poisoned input can cause the agent to run attacker-shaped commands, then use that execution path to reach data, services, or credentials the designer never meant to expose.
Failure mechanism: The attacker influences the agent's generated instructions or tool chain, then exploits permissive execution, weak sandboxing, or missing approval gates to make unintended code run.
Impact: The result can be code execution, data exfiltration, service abuse, environment tampering, or broader compromise if the agent can reach sensitive systems or secret material.
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 addresses 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 | ASI05 — Unexpected Code Execution | Directly defines this agentic code-execution risk and its containment controls. |
| Recommendation — Constrain agent execution paths, sandbox runtime actions, and require approval for high-impact commands. | ||
| NIST SP 800-53 Rev 5 | SI-10 — Information Input Validation | Validates untrusted inputs before they become executable actions. |
| AC-6 — Least Privilege | Limits the damage if an agent executes unintended commands. | |
| SC-7 — Boundary Protection | Supports sandboxing and egress restriction for agent execution environments. | |
| Recommendation — Validate and constrain model-derived inputs before they reach interpreters or command execution paths. Restrict agent permissions to the minimum needed for the task and environment. Isolate agent runtimes and limit outbound connections and trust boundaries. | ||
Practitioner Guidance
Why practitioners should care: ASI05 is not solved by better prompts alone, because the real issue is where generated instructions are allowed to execute. Treat any agent that can run code as an application with a privileged execution surface, not just a chat interface.
What to watch for: Review whether the agent can spawn shells, invoke interpreters, write executable files, or call administrative tools without a separate policy check. If the answer is yes, the system needs tighter containment and clearer approval boundaries before it is safe to rely on.
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 26, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org