CVE-2026-34937
Command injection in PraisonAI run_python due to improper shell escaping.
- CVSS 9.8
- CWE-78
- Input Validation and Sanitization
- Remote
PraisonAI is a multi-agent teams system. Prior to version 1.5.90, run_python() in praisonai constructs a shell command string by interpolating user-controlled code into python3 -c "<code>" and passing it to subprocess.run(…, shell=True). The escaping logic only handles \ and ", leaving $() and backtick substitutions unescaped, allowing arbitrary OS command execution before Python is invoked. This issue has been patched in version 1.5.90.
- CWE
- CWE-78
- CVSS base score
- 9.8
- Published
- 2026-04-03
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Incorrect Check
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- PraisonAI
- Fixed by upgrading
- Yes
Solution
Upgrade PraisonAI to version 1.5.90 or later.
Vulnerable code sample
import subprocess
def run_python(code: str):
"""
This function represents the vulnerable state of PraisonAI's run_python
prior to version 1.5.90, as described in CVE-2026-34937.
"""
# Flawed escaping that only handles backslashes and double quotes, leaving
# shell command substitution characters like $() and `` unescaped.
escaped_code = code.replace("\\", "\\\\").replace("\"", "\\\"")
# Insecurely constructs a shell command by embedding the escaped code.
command = f'python3 -c "{escaped_code}"'
# The use of shell=True with the improperly sanitized 'command' string
# creates a command injection vulnerability. The shell will process
# substitutions like $(command-to-run) before invoking python3.
result = subprocess.run(
command,
shell=True,
capture_output=True,
text=True,
check=False
)
return resultPatched code sample
import subprocess
import shlex
def run_python(code: str):
"""
Executes a string of Python code in a secure manner, demonstrating the
fix for a command injection vulnerability.
The vulnerability (CVE-2026-34937) was caused by using `shell=True` with an
improperly sanitized, user-controlled string. The fix is to avoid the
shell entirely for command execution by passing arguments as a sequence.
By setting `shell=False` (which is the default) and passing the command
and its arguments as a list (`['python3', '-c', code]`), the user-provided
`code` string is treated as a single argument to `python3 -c` and is not
interpreted by the shell. This prevents shell metacharacters like `$` or
backticks from being executed as commands.
"""
try:
# The command and its arguments are passed as a list.
# `shell=False` is the default and is the secure way to call subprocesses
# when arguments are involved, as it prevents shell injection.
command_args = ["python3", "-c", code]
result = subprocess.run(
command_args,
capture_output=True,
text=True,
check=False, # Do not raise exception for non-zero exit codes
timeout=10 # Add a timeout for safety
)
return result.stdout, result.stderr
except subprocess.TimeoutExpired:
return "", "Error: Code execution timed out after 10 seconds."
except Exception as e:
return "", f"An unexpected error occurred: {e}"Payload
$(touch /tmp/pwned)
Cite this entry
@misc{vaitp:cve202634937,
title = {{Command injection in PraisonAI run_python due to improper shell escaping.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-34937},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-34937/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
