Summary
A critical code-injection vulnerability in PraisonAI's codeMode tool allows model-influenced JavaScript to execute with the privileges of the PraisonAI process. The risk arises when an attacker can influence the tool's code argument, potentially enabling host access, file operations, credential exposure, and operating-system command execution.
Affected context
The vulnerability occurs in PraisonAI deployments using the codeMode tool before the security fix was applied. The tool executes model-generated JavaScript with a sandboxing pattern and relies on a regular-expression blocklist, which may be insufficient to prevent access to host capabilities when attacker-controlled or attacker-influenced code reaches the execution path.
Exploit preconditions
- Attack surface: PraisonAI's codeMode tool and its JavaScript execution path
- Required access: The ability to influence the code argument or otherwise control model-generated code submitted to the tool
- Trigger point: Execution of the supplied JavaScript by the codeMode implementation
- Why exploitation is possible: The blocklist does not reliably enforce a complete execution boundary, allowing restricted capabilities to be reached through alternative language and runtime behaviors
Why this happens
The underlying flaw is the execution of model-generated JavaScript through dynamic function construction and a with-based sandbox while treating a regular-expression blocklist as the primary control. This pattern does not provide a reliable capability boundary: JavaScript runtime features may expose global objects or enable indirect access to powerful host modules. The issue maps to CWE-94: Improper Control of Generation of Code, because input that can be influenced by an attacker is executed as program logic.
Potential impact
- An attacker could execute operating-system commands with PraisonAI process privileges
- The process could read or modify accessible files
- Environment variables and embedded credentials may be exposed
- The host or workload could be compromised
- Connected agents, tools, and data sources could be manipulated
- The vulnerability could enable lateral movement where excessive permissions are available
General mitigation guidance
Mitigation generally focuses on removing unrestricted code execution from application trust boundaries and replacing blacklist-based filtering with explicit capability controls.
Common defensive patterns include:
- Avoiding dynamic evaluation of model-generated or untrusted JavaScript
- Running unavoidable code execution in an isolated, minimally privileged sandbox with a narrow allowlist of capabilities
- Separating tool execution from sensitive host resources and credentials
- Restricting filesystem, network, process, and module access by default
- Treating model output as untrusted data and applying structured schemas before invoking tools
- Running the service with a dedicated low-privilege identity and minimal environment secrets
- Applying resource limits, auditing, and containment around code-execution workers
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules targeting
new Function,eval, dynamic module loading, and sandbox implementations based on textual blocklists - Code review checks for model output flowing directly into interpreters or operating-system interfaces
- Dependency and policy scanning for tools that expose unrestricted host capabilities to generated code
- Runtime monitoring of child-process creation, unusual file access, module loading, and outbound connections
- CI policies requiring explicit security review for code-execution features and privileged tool integrations
- Automated code review tools that flag dynamic code generation and untrusted data reaching execution sinks

