AI agents are evolving beyond conversational assistants into autonomous systems capable of writing code, executing scripts, interacting with development environments, managing cloud infrastructure, and performing complex business operations. These capabilities can significantly improve productivity. However, they also introduce security risks when AI agents execute code without adequate validation, authorization, or isolation.
Attackers exploit code-generation features or embedded tool access to escalate actions into remote code execution (RCE), local misuse, or exploitation of internal systems. Because this code is often generated in real-time by the agent it can bypass traditional security controls.
Unlike traditional remote code execution vulnerabilities, which often exploit software flaws, agentic AI systems can introduce an additional attack path, such as manipulating an AI agent’s decisions so that it voluntarily invokes legitimate code-execution tools for malicious purposes.
What is ASI05: Unexpected Code Execution (RCE)?
ASI05: Unexpected Code Execution (RCE) describes the risk of AI agents executing unauthorized, unintended, or attacker-influenced code through their access to interpreters, terminals, development environments, automation tools, or connected systems.
An attacker may exploit an agent’s ability to interpret untrusted content, generate executable instructions, install dependencies, or invoke powerful tools.
Common Examples of the Vulnerability
- Prompt injection that leads to execution of attacker-defined code.
- Code hallucination generating malicious or exploitable constructs.
- Shell command invocation from reflected prompts.
- Unsafe function calls, object deserialization, or code evaluation.
- Use of exposed, unsanitized eval() functions powering agent memory that have access to untrusted content.
- Unverified or malicious package installs can escalate beyond supply-chain compromise when hostile code executes during installation or import.
The Unexpected Code Execution (RCE) security concern: An AI agent may transform untrusted information into executable actions without sufficient security controls.
Attack Scenario Examples
Scenario 1: Auto-GPT executes attacker-controlled code and escapes a container
Attack vector: Prompt injection through a malicious webpage.
An autonomous AI agent is assigned a routine task that requires browsing external websites. During the task, it encounters attacker-controlled content containing instructions to download and execute a script. If the agent treats these instructions as legitimate task requirements, it may invoke its code-execution tools and run the script inside its environment.
Impact: Full RCE and Docker container escapes using the agent’s legitimate execution capabilities.
Source: NIST – Agentic AI Emerging Threats, Mitigations, and Challenges.
Scenario 2: GitHub Copilot Agent manipulated into executing shell commands
Attack vector: Prompt injection combined with insecure agent hook configuration.
In August 2026, Microsoft disclosed a remote code execution vulnerability affecting GitHub Copilot agent functionality in Visual Studio Code. A crafted prompt injection could cause an agent to write custom agent configuration files containing malicious lifecycle hooks without obtaining the expected user confirmation.
When the affected custom agent was subsequently invoked, the hook could execute attacker-controlled shell commands using the privileges of the person running VS Code.
The vulnerability was fixed in VS Code 1.132.1.
Source: Microsoft VS Code Security Advisory – Copilot Custom Agent Hook RCE
Attack vector: Malicious instructions embedded in repository content.
A developer asks an AI coding assistant to review a project, troubleshoot a deployment issue, or update application dependencies. The repository contains a README file or AI-specific configuration file with instructions that appear to be legitimate project setup requirements.
An attacker who controls this content can attempt to convince the agent to run unnecessary shell commands, install untrusted dependencies, or modify sensitive configuration files.
Source: README Injection: Repository Files Hijacking AI Coding Assistants
Scenario 4: Cloud Automation Agent executes an unsafe remediation script
Attack vector: Untrusted diagnostic output influencing an agent’s code-generation decisions.
An organization deploys an AI cloud operations agent to investigate performance issues across AWS, Microsoft Azure, or Google Cloud. While analyzing diagnostic logs, the agent encounters attacker-controlled content suggesting that a particular remediation script must be executed to restore service.
If the agent can execute unrestricted shell commands or modify cloud workloads without independent authorization checks, it may run the script and compromise its operating environment.
Source: Microsoft – OWASP ASI05 Unexpected Code Execution Security Reference.
Prevention and Mitigation Guidelines
Preventing unexpected code execution requires more than filtering malicious prompts. Organizations must implement security controls around the entire code-execution lifecycle, from untrusted input and code generation to runtime execution, authorization, and monitoring.
1. Execute AI-generated code in isolated environments
AI-generated scripts and commands should run inside dedicated, restricted execution environments rather than directly on production servers or developer workstations.
2. Apply least privilege to agent execution environments
Agents should have only the permissions required for their assigned tasks. Use dedicated workload identities, narrowly scoped permissions, and temporary credentials where possible.
3. Treat external content as untrusted data
Repositories, webpages, documentation, issue comments, logs, retrieved documents, and tool outputs should never automatically become authoritative instructions for code execution.
4. Require human approval for high-risk execution
Introduce explicit authorization checkpoints before agents perform sensitive operations, including executing scripts with elevated privileges, installing software, changing security configurations, or deploying code to production.
5. Avoid unsafe code evaluation and deserialization
Do not pass untrusted agent outputs into unrestricted code-evaluation functions, shell interpreters, template engines, or unsafe deserialization mechanisms.
AI Autonomy must not mean unrestricted execution
At Reputiva, we believe one of the most important security boundaries in agentic AI is the boundary between what an AI agent recommends and what it is permitted to execute.
AI agents are becoming valuable contributors to software development, cloud operations, security monitoring, and IT automation. However, giving an agent the ability to generate code should not automatically grant it the authority to execute that code across sensitive environments.
For organizations adopting AI-powered automation, three questions should guide their security architecture:
-
What can the agent execute? Are its commands, tools, and APIs restricted to approved operations?
-
Where can the agent execute it? Is code execution isolated from production workloads, sensitive data, and privileged credentials?
-
Who authorizes and monitors execution? Are high-risk operations subject to independent authorization, approval, and audit logging?
Secure Your AI Agents Before They Execute More Than Intended
As organizations adopt autonomous AI agents, code execution security must become a core component of their cybersecurity and AI governance strategies.
Reputiva helps organizations strengthen their security posture through cloud security assessments, identity and access management, AI security advisory, and secure architecture design across AWS, Microsoft Azure, and Google Cloud.
Whether your organization is deploying AI coding assistants, integrating autonomous agents into business workflows, or exploring AI-powered cloud operations, understanding the security implications of code execution is essential.
Ready to assess the security risks of your AI agents? Book a Consultation today
Reputiva
Reputiva is a cloud, cybersecurity, and FinOps advisory firm helping SMEs reduce cyber risk, strengthen cloud environments, and manage technology costs with confidence. We publish practical insights on cloud security, identity, AI risk, compliance, and digital transformation.


