# ASI05 - Unexpected Code Execution

> Agent generates and executes code or commands that compromise the host system.

- **Category**: Owasp Agentic Ai
- **Subcategory**: top10_2026
- **Canonical URL**: https://designpattern.fyi/owasp_agentic_ai/asi05_unexpected_code_execution/

---

## Description
'**Intent**: Prevent agents from executing arbitrary or malicious code that could compromise the underlying system.

**Context**: Agents with code execution capabilities can be manipulated into generating and running harmful code, including system commands, file operations, or network requests.

**Solution**: Sandbox all code execution environments. Use allowlists for permitted operations. Implement code review before execution. Apply resource limits. Monitor executed code. Use containerized execution with minimal permissions.'



## Use Cases
Use when agents can generate, modify, or execute code, scripts, or system commands.





## Trade-offs


### Advantages

- Prevents system compromise

- Limits code execution scope

- Enables execution auditing

- Supports safe code generation




### Considerations & Drawbacks

- Sandboxing reduces capabilities

- Code review adds latency

- Allowlists require maintenance







---
**Reference**: [Original Source](https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026)

