Summary
PraisonAI's CodeAgent component can be coerced into executing arbitrary Python code generated by a large language model without any validation or sandboxing.
When an attacker injects malicious prompts, they can steer the LLM to produce code that runs on the host, exfiltrating environment secrets and achieving full remote code execution.
Affected context
This vulnerability occurs in PraisonAI deployments that use the CodeAgent._execute_python() capability to run LLM-generated Python code directly on the host.
Risk is elevated when:
- The LLM is exposed to untrusted user input or external content
- Environment variables or secrets are accessible to the process
- No sandbox, import restriction, or execution policy is enforced around the agent
Exploit preconditions
- Attack surface: Any interface (chat, API, workflow) that feeds untrusted input into the LLM driving CodeAgent._execute_python()
- Required access: Ability to supply or influence prompts or context consumed by the LLM
- Trigger point: Invocation of the CodeAgent that causes unvalidated Python code to be executed on the host
- Why exploitation is possible: The agent executes LLM-generated Python without AST inspection, import controls, or sandboxing, so injected instructions can be translated into arbitrary code that the host blindly runs
Why this happens
The underlying issue is direct execution of dynamically generated code with no validation or confinement, matching CWE-94: Improper Control of Generation of Code ('Code Injection').
PraisonAI's CodeAgent treats LLM output as trusted source code, executing it via Python without:
- Parsing or constraining the abstract syntax tree (AST)
- Restricting imports, file access, or network operations
- Enforcing sandbox boundaries or least privilege
This design creates an execution path where attacker-controlled prompts can become executable Python, turning a text interface into a remote shell on the host.
Potential impact
- Full remote code execution on the host running PraisonAI
- Exfiltration of environment variables, API keys, and other secrets
- Unauthorized access to local files, databases, and internal services
- Installation of backdoors or persistence mechanisms on the system
- Use of the compromised host as a pivot for lateral movement within the network
General mitigation guidance
Effective mitigation focuses on breaking the direct trust relationship between LLM output and code execution.
Pattern-based defensive strategies include:
- Introducing strict AST-based validation and allowlists of safe constructs before any generated code is executed
- Enforcing import and capability restrictions so generated code cannot access sensitive modules, files, or networks by default
- Running code agents inside an isolated sandbox (e.g., container, VM, or restricted interpreter) with minimal privileges and no direct access to host secrets
- Applying strong input trust reduction: treat all user-supplied prompts and external context as untrusted, and avoid binding them directly to high-privilege automation
- Separating duties so that LLM-generated code is subject to human or automated review steps before execution in sensitive environments
How teams detect issues like this
Detection typically involves identifying dangerous code-generation and execution paths rather than specific payloads.
Common approaches include:
- Static analysis rules that flag use of generic
exec,eval, or equivalent dynamic execution in agent components without prior validation - Code review checklists that require AST inspection, sandboxing, and capability restriction for any LLM-integrated code execution feature
- Runtime monitoring of agent processes for unusual file access, network connections, or secret retrieval patterns triggered by LLM workflows
- Policy enforcement in CI/CD to block deployments where LLM output can reach execution sinks without intermediate safety controls
- Use of automated security testing tools to simulate prompt injection and verify that generated code cannot escape its intended sandbox

