Summary
PraisonAI versions prior to 4.6.78 contain a code injection flaw where the agents_file parameter is directly interpolated into an f-string and later executed as Python code.
An attacker who can influence this parameter may execute arbitrary Python instructions when the generated server code is launched via subprocess.Popen().
Affected context
The vulnerability appears in the deployment API path of PraisonAI, specifically within deploy/api.py where dynamic server code is generated.
It is relevant in environments that programmatically construct server-side Python code from user-influenced inputs, and then start that code using subprocess.Popen() or similar execution mechanisms.
The risk is most pronounced when agents_file can be supplied or modified by external clients, configuration interfaces, or automation pipelines without strong validation or isolation.
Exploit preconditions
- Attack surface: API or configuration interface that sets the
agents_fileparameter used bydeploy/api.py. - Required access: Ability to control or significantly influence
agents_file(e.g., via HTTP requests, CLI arguments, or config files). - Trigger point: Code generation step that interpolates
agents_fileinto an f-string and subsequently launches the resulting script viasubprocess.Popen(). - Why exploitation is possible: The application treats
agents_fileas trusted, directly embedding it into executable Python code without sanitization, escaping, or separation of code and data.
Why this happens
This issue stems from dynamically constructing Python source code using untrusted data and then executing that code.
By interpolating agents_file into an f-string, the application allows attacker-controlled content to become part of the program logic itself rather than remaining plain data.
This pattern maps to CWE-94: Improper Control of Generation of Code, where user input influences code generation or execution paths, enabling arbitrary code execution if not strictly constrained.
Potential impact
- Execution of arbitrary Python code under the PraisonAI service account
- Reading, modifying, or deleting application and user data accessible to the process
- Pivoting to the underlying host or container environment, depending on permissions
- Deployment of backdoors, logic tampering, or persistent malicious behavior in generated servers
- Disruption or denial of service by crashing or overloading the deployment process
General mitigation guidance
Mitigation focuses on ensuring that untrusted input cannot be treated as executable code.
Common defensive approaches include:
- Avoiding dynamic code generation where possible, or constraining it to fixed templates with strictly validated parameters.
- Treating
agents_fileand similar parameters as pure data, passing them as arguments or configuration values rather than embedding them into code strings. - Applying allowlisting and strict parsing for file names, identifiers, and paths, rejecting unexpected characters or constructs.
- Isolating any unavoidable code generation in a tightly sandboxed, least-privilege environment with minimal access to sensitive resources.
- Designing deployment mechanisms to use structured configuration formats (e.g., JSON, YAML) instead of string-based code templates.
How teams detect issues like this
Detection typically involves reviewing both code patterns and runtime behavior:
- Static analysis rules that flag string interpolation or concatenation used to build Python source code, especially when combined with
exec,eval, dynamic imports, or subprocess execution. - Code review checklists that highlight any use of user-controlled inputs in f-strings or templates that ultimately produce executable code.
- Enforcement of policies banning dynamic code evaluation in deployment logic, backed by automated checks in CI/CD pipelines.
- Runtime monitoring for unusual subprocess invocations or unexpected Python scripts launched by the deployment component, which may indicate exploitation attempts.

