/

CVE-2026-34937

Severity:

HIGH RISK

(7.8)

OS Command Injection in PraisonAI run_python Shell Wrapper

CVE-2026-34937

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Code Execution via Shell Command Injection

Severity:

HIGH RISK

(7.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

PraisonAI's run_python() helper constructs a shell command by interpolating user-controlled code into a python3 -c "<code>" string and executing it with shell=True.

Because shell metacharacters like $() and backticks are not safely escaped, an attacker who can influence the code string may execute arbitrary operating system commands before Python is even invoked.

Affected context

This vulnerability arises in PraisonAI deployments that use the run_python() function to execute dynamically provided Python code through a shell wrapper.

The risk is highest when:

  • User input, agent-generated content, or other untrusted data is passed into run_python()
  • The application runs with elevated OS privileges or access to sensitive resources
  • There is no strict validation or sanitization of the code argument before it reaches the shell

In such contexts, what appears to be "Python-only" execution actually traverses a general-purpose shell, exposing a broader attack surface.

Exploit preconditions

  • Attack surface: Any interface (API, UI, agent, plugin, or workflow) that passes untrusted or partially trusted strings into run_python().
  • Required access: Ability to influence the code parameter supplied to run_python(), either directly or indirectly (e.g., via prompt injection into an agent).
  • Trigger point: Invocation of run_python() which builds a command like python3 -c "<code>" and calls subprocess.run(..., shell=True).
  • Why exploitation is possible:
  • The shell interprets $() and backtick (`) syntax as command substitution.
  • The escaping logic only handles backslashes and double quotes, leaving shell metacharacters intact.
  • With shell=True, the constructed string is processed by /bin/sh (or equivalent), allowing embedded OS commands to run before Python executes.

Why this happens

The underlying bug is a classic OS command injection pattern aligned with CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

Instead of invoking Python directly with a structured API (e.g., passing arguments as a list), run_python():

  • Builds a single shell command string that includes untrusted data.
  • Uses shell=True, handing the string to a command interpreter.
  • Implements incomplete escaping that focuses on \ and " but ignores other shell metacharacters, especially command substitution constructs.

This leads the shell to treat parts of the supplied "code" as first-class commands, blurring the line between Python execution and OS control and enabling attackers to break out of the intended Python-only context.

Potential impact

  • Execution of arbitrary OS commands with the privileges of the PraisonAI process.
  • Reading, modifying, or deleting local files accessible to the application.
  • Exfiltration of environment variables, API tokens, credentials, or configuration secrets.
  • Pivoting into internal networks or lateral movement to other services from the compromised host.
  • Denial of service by exhausting system resources, terminating critical processes, or corrupting local state.

General mitigation guidance

Effective mitigation centers on removing shell interpretation from the execution path and tightening the trust boundary around dynamic code:

  • Prefer direct process invocation over shell usage:
  • Call Python (or any interpreter) using argument lists (e.g., subprocess.run([...], shell=False)).
  • Avoid constructing shell command strings from untrusted data altogether.
  • Eliminate or strictly limit dynamic code execution:
  • Reduce or remove features that execute arbitrary code derived from prompts or user input.
  • Where dynamic execution is required, constrain it to well-defined, pre-approved operations or scripts.
  • Apply rigorous input handling:
  • Treat all inputs to run_python()-style helpers as untrusted by default.
  • Enforce allowlists or structured formats instead of free-form strings.
  • Run with least privilege:
  • Ensure the PraisonAI process runs as a non-privileged user with minimal filesystem and network permissions.
  • Isolate high-risk execution in sandboxed environments or containers with restricted capabilities.
  • Design secure-by-default abstractions:
  • Provide high-level APIs that perform work without exposing direct shell or interpreter controls to user-provided strings.
  • Make unsafe patterns (dynamic shell commands, raw code strings) harder to use than safe alternatives.

How teams detect issues like this

Organizations can pursue several high-level strategies to uncover and monitor similar issues:

  • Static analysis and linting:
  • Flag uses of subprocess (or equivalents) where shell=True is combined with variables influenced by user input.
  • Detect string interpolation or concatenation patterns that build command lines from external data.
  • Code review practices:
  • Treat any helper that wraps command execution or dynamic code evaluation as security-sensitive.
  • Require explicit review for functions that accept "code" or "command" arguments, checking for shell involvement.
  • Secure coding guidelines and policy:
  • Establish rules that discourage shell=True in production code without a documented, reviewed justification.
  • Mandate the use of argument lists for process invocation and enforce them in CI via linters or custom checks.
  • Runtime monitoring:
  • Log invocations of command execution wrappers along with callsites or context.
  • Use host-level monitoring (e.g., EDR, syscall auditing) to detect unexpected commands originating from application processes.

Sources

SourceLink
github.comgithub.com/MervinPraison/PraisonAI/security/advisories/GHSA-w37c-qqfp-c67f

Frequently asked

questions

It can be, depending on how PraisonAI is integrated. If remote users, agents, or external systems can influence the code passed into run_python(), then they may be able to trigger OS command execution over the network. If only fully trusted components can call run_python() with controlled input, the practical exposure is narrower.

An attacker needs the ability to control or significantly influence the string passed to run_python(). This might be direct (e.g., an API parameter or web form) or indirect (e.g., prompt injection in an LLM workflow where agent responses are fed into run_python() without strict validation).

The most robust fix is to remove shell interpretation entirely: avoid shell=True and invoke Python (or other tools) using structured argument lists where untrusted data is passed as data, not as part of a command line. Additionally, avoid supporting arbitrary code strings; instead route through constrained, predefined operations.

Prevention involves a combination of design and process:

  • Design APIs that do not require building shell commands from untrusted input.
  • Enforce coding standards that prohibit shell=True for dynamic content, backed by linters and CI checks.
  • Treat any feature that executes dynamic code as high risk, requiring threat modeling and security review.
  • Educate developers on common injection patterns and encourage use of safe abstractions for command and code execution.
Find out what's already
exploitable in your codebase.