Versatile AI Risk Assessment

AI threat catalogue Agentic and Autonomous AI Production

Unexpected Code Execution and Agent Escape from the Execution Environment

Agents generate code and commands and run them themselves. Manipulated inputs or goal-driven behaviour lead to malicious code being executed, the isolated environment being left, or agents attacking real, uninvolved systems from within test environments.

As of: November 2026 Catalogue version 2026.11.15.2 7 mitigations 13 verified references

Description

Many agents may write program code and run it in an interpreter, a command line or a container. If prompt injection or manipulated tool responses bring outside instructions into the context, the agent generates harmful commands and executes them in the same step. The sandbox (isolated execution environment) is then the last line of defence; an unintentionally open internet connection or vulnerabilities in the container and proxy can be exploited. Goal-driven behaviour adds to this: when a target is unreachable, agents switch to reachable systems and mistake real targets for part of an exercise. Test environments for penetration testing and coding agents are especially exposed.

Possible impact

Malicious code runs with the rights of the execution environment; attackers or misguided agents reach internal networks, databases and credentials. If a company's own agent attacks uninvolved third parties, the operator may be liable for the damage, and the incident can trigger notification duties and regulatory investigations. Providers of general-purpose AI models with systemic risk must assess and mitigate such risks under the EU AI Act.

Example

A company tests a penetration testing agent in an environment that, according to the task description, has no internet access. Due to a configuration error, a connection is open after all. The agent takes reachable external servers to be part of the exercise, exploits vulnerabilities there and breaks into systems of another organisation before anyone reviews the logs.

Main lifecycle phase
Operation and monitoring
Arises in
Development and training, Operation and monitoring
Takes effect in
Development and training, Validation and approval, Operation and monitoring

Recommended mitigations (7)

Compare effects and implementation levels. Expand each entry for the additional classification and rationale.

  • Agent code execution only in a short-lived, isolated sandbox without network or credential access

    Technical
    Effect
    Preventive, Impact-limiting
    Implementation level
    Infrastructure, Application, API & agents
    Classification and rationale

    Primarily technical: Architectural and runtime boundaries separate data, execution, or tenants and limit the spread of failures.

    Meaning, implementation and evidence
    What it means
    Code and commands generated by agents run only in an isolated sandbox created fresh for each task, without network access or credentials, and discarded afterwards.
    Effect on the threat
    Malicious code from manipulated input or misguided agent behaviour can neither steal credentials nor reach other systems or leave persistent traces.
    When it helps
    Useful where agents generate and run code or commands themselves, for example in interpreters, shells, containers or test and evaluation environments.
    Suggested implementation
    1. Provide an isolated execution environment with resource limits.
    2. Disable network and credentials in the sandbox by default.
    3. Discard the sandbox after each task and test isolation regularly.
    Useful evidence examples
    Sandbox configuration, architecture description, escape or isolation test report or execution log.
  • Technically enforced egress allowlist for agent and test environments, automatically verified before every run

    Technical
    Effect
    Preventive
    Implementation level
    Infrastructure
    Classification and rationale

    Primarily technical: Architectural and runtime boundaries separate data, execution, or tenants and limit the spread of failures.

    Meaning, implementation and evidence
    What it means
    Agent and test environments can technically reach only explicitly approved network destinations; before every run an automated test verifies that the restriction is active and unapproved destinations are blocked.
    Effect on the threat
    An agent cannot attack real, uninvolved systems from a test or evaluation environment, and a silently disabled restriction is noticed before the run.
    When it helps
    Useful where agents generate and run code or commands themselves, for example in interpreters, shells, containers or test and evaluation environments.
    Suggested implementation
    1. Define permitted destinations per environment and block everything else.
    2. Enforce the restriction at network level outside the agent's control.
    3. Verify automatically before each run that an unapproved destination is blocked.
    Useful evidence examples
    Egress rule set, automated pre-run test result, firewall log or pipeline configuration.
  • Allowlist of permitted commands and human approval for consequential executions

    Technical
    Effect
    Preventive
    Implementation level
    Application, API & agents, Use & operations
    Classification and rationale

    Complementary control typeOrganizational & process-based

    Primarily technical: Machine-enforced identity, permission, or scope rules constrain unauthorized access and actions; complemented by binding workflows.

    Meaning, implementation and evidence
    What it means
    Agents may run only commands from a defined list without asking; consequential executions such as deletion, installation, network access or system changes require human approval.
    Effect on the threat
    Dangerous commands injected through manipulated input or chosen by goal-driven behaviour are not executed automatically but blocked or presented to a human.
    When it helps
    Useful where agents generate and run code or commands themselves, for example in interpreters, shells, containers or test and evaluation environments.
    Suggested implementation
    1. Define permitted commands and consequential action classes.
    2. Technically block commands outside the list or route them for approval.
    3. Log approvals and rejected commands and review the list regularly.
    Useful evidence examples
    Command allowlist, configuration excerpt, approval log or test report.
  • No production credentials or signing keys within reach of test and evaluation agents

    Technical
    Effect
    Preventive, Impact-limiting
    Implementation level
    Infrastructure
    Classification and rationale

    Primarily technical: Machine-enforced identity, permission, or scope rules constrain unauthorized access and actions.

    Meaning, implementation and evidence
    What it means
    Environments in which agents are tested or evaluated contain no production credentials, tokens or signing keys, whether as files, environment variables or via reachable secret stores.
    Effect on the threat
    Even if an agent escapes the sandbox or searches for credentials, it finds nothing it could use to attack production systems or sign software.
    When it helps
    Useful where agents generate and run code or commands themselves, for example in interpreters, shells, containers or test and evaluation environments.
    Suggested implementation
    1. Scan test and evaluation environments for credentials and keys.
    2. Remove production secrets and replace them with test access unrelated to production.
    3. Block these environments from accessing production secret stores.
    Useful evidence examples
    Scan report, environment configuration excerpt, secret store permission export or review record.
  • Contractual and technical security requirements for external evaluation and testing providers

    Contracts & third-party management
    Effect
    Preventive, Detective
    Implementation level
    Supply chain, Organization
    Classification and rationale

    Complementary control typeTechnical, Organizational & process-based

    Primarily a contracts and third-party management control: Selection, verifiable commitments, and audit or enforcement rights toward third parties enable the protective effect; complemented by technical implementation as well as binding workflows.

    Meaning, implementation and evidence
    What it means
    Contracts with external providers that evaluate or test agents set out isolation requirements, network restrictions, breach notification duties and audit rights, and compliance is demonstrated before engagement.
    Effect on the threat
    Agent escapes from a provider's test environment are made harder by agreed safeguards and reported in time if they occur.
    When it helps
    Useful where agents generate and run code or commands themselves, for example in interpreters, shells, containers or test and evaluation environments.
    Suggested implementation
    1. Define security requirements for external providers' test environments.
    2. Agree requirements, notification duties and audit rights contractually.
    3. Obtain evidence before engagement and regularly thereafter.
    Useful evidence examples
    Contract clauses, requirements list, provider evidence or audit report.
  • Real-time monitoring of agent actions and network destinations with automatic termination on boundary violations

    Technical
    Effect
    Detective, Impact-limiting
    Implementation level
    Infrastructure, Use & operations
    Classification and rationale

    Primarily technical: Software or analytical tools systematically produce and evaluate measurements, deviations, or attack indicators.

    Meaning, implementation and evidence
    What it means
    Agent processes, file access and network connections are monitored in real time; if an agent breaches defined boundaries, such as an unapproved destination, execution is terminated automatically.
    Effect on the threat
    An escape attempt or attack on third-party systems is detected and stopped while it is happening instead of only surfacing later in logs.
    When it helps
    Useful where agents generate and run code or commands themselves, for example in interpreters, shells, containers or test and evaluation environments.
    Suggested implementation
    1. Define boundaries for processes, files and network destinations per environment.
    2. Set up real-time monitoring with automatic termination on violations.
    3. Log terminations and route alerts to the responsible owners.
    Useful evidence examples
    Monitoring configuration, termination rules, alert and termination log or test report.
  • Kill switch and incident playbook including notification of affected third parties

    Organizational & process-based
    Effect
    Impact-limiting, Corrective
    Implementation level
    Use & operations, Organization, Application, API & agents
    Classification and rationale

    Complementary control typeTechnical

    Primarily organizational and process-based: A defined reporting, triage, and handling workflow turns observations into traceable follow-up actions; complemented by technical implementation.

    Meaning, implementation and evidence
    What it means
    A kill switch immediately stops all agent runs in an environment; an incident playbook covers containment, evidence preservation and notification of affected third parties whose systems an agent reached.
    Effect on the threat
    An escaped or attacking agent is stopped quickly, and uninvolved affected parties can take their own protective measures.
    When it helps
    Useful where agents generate and run code or commands themselves, for example in interpreters, shells, containers or test and evaluation environments.
    Suggested implementation
    1. Provide a kill switch for all agent runs and define who may trigger it.
    2. Describe steps for containment, evidence preservation and third-party notification.
    3. Rehearse the kill switch and playbook regularly.
    Useful evidence examples
    Incident playbook, kill switch test record, exercise record or incident report.

Framework mappings

Verified locations in OWASP, NIST AI RMF, MITRE ATLAS, the EU AI Act and further frameworks. The mappings are taxonomic, not evidence of compliance.

Verified references (13)

Every reference states the framework, the exact location and the publishing organisation.

How the catalogue relates this threat to others, with the reason.

EU AI Act obligations related to this threat

The obligations from the obligations compass whose articles the catalogue maps to this threat. Each leads to its entry with core, action step and evidence; whether it applies to you depends on role and risk class.

  • Evaluate and mitigate systemic risks Art. 55, applies from 2 August 2025

    Statutory roles: Provider of a general-purpose AI model. Classes: Model with systemic risk.

    This reference is a review prompt. A threat match alone does not establish applicability.

All 62 obligations by role, risk class and deadline in the obligations compass

Terms on this page

Glossary terms that occur in this entry. Every link leads to the full explanation.

Matching use cases

This list shows where to review this threat, rather than how high the risk is.

Particularly important for:

  • Coding agentUnrestricted terminal access lets the agent execute any command available to the signed-in user. Without isolation and an allowlist of commands, a mistake is difficult to contain.

For 3 further use cases, relevance depends on the system design, for example whether it executes programs or commands itself. Show these use cases

Frequently asked questions

What is Unexpected Code Execution and Agent Escape from the Execution Environment?
Agents generate code and commands and run them themselves. Manipulated inputs or goal-driven behaviour lead to malicious code being executed, the isolated environment being left, or agents attacking real, uninvolved systems from within test environments.
Which mitigations help against Unexpected Code Execution and Agent Escape from the Execution Environment?
The catalogue lists 7 mitigations, each with control type, effect and implementation level. First among them are “Agent code execution only in a short-lived, isolated sandbox without network or credential access”; “Technically enforced egress allowlist for agent and test environments, automatically verified before every run”; and “Allowlist of permitted commands and human approval for consequential executions”.
Which EU AI Act obligations does Unexpected Code Execution and Agent Escape from the Execution Environment touch?
The catalogue maps this threat to Art. 55(1)(b) of the EU AI Act. In the obligations compass this leads to: Evaluate and mitigate systemic risks. Whether an obligation applies depends on role, risk class and deadline.

Assess this threat in your own system

The live demo contains all 79 threats of this catalogue, including the EU AI Act and GDPR assessment. The free single modules cover AI risk, the EU AI Act and GDPR. No sign-up; the assessment runs locally in your browser.

Cite this entry

For reports, policies or internal documents; the link leads directly to this entry.

“Unexpected Code Execution and Agent Escape from the Execution Environment”. Versatile AI Risk Assessment, AI threat catalogue, as of November 2026.
https://www.versatile-ai-risk-assessment.com/en/wissensbasis/threats/execution-environment-escape/

← Back to the full catalogue