PraisonAI SubprocessSandbox Shell Escape via sh/bash
PraisonAI's SubprocessSandbox allows attackers to bypass command restrictions due to the use of `shell=True` in `subprocess.run()` combined with an insufficient blocklist that does not include `sh` or `bash`, enabling command execution via `sh -c '<command>'`.
PraisonAI’s SubprocessSandbox, even in STRICT mode, is vulnerable to a sandbox escape. The vulnerability arises from the use of subprocess.run() with shell=True in sandbox_executor.py, coupled with an insufficient blocklist that fails to include sh and bash as standalone executables. This oversight allows attackers to bypass the intended command restrictions by executing arbitrary commands through sh -c '<command>'. Versions of PraisonAI up to 4.5.96 are affected. This means that any command blocked by the configured policy can be trivially executed, which could allow agent prompt injection attacks to lead to full system compromise.
Attack Chain
- An attacker crafts a malicious command to be executed within the PraisonAI environment.
- The PraisonAI application receives the crafted command and attempts to execute it within the
SubprocessSandbox. - The
SubprocessSandboxusessubprocess.run()withshell=Trueto execute the provided command. - The blocklist in
sandbox_executor.pyfails to block theshorbashcommands themselves. - The attacker injects shell commands via
sh -c '<blocked_command>', bypassing the string-pattern matching intended to restrict execution. - The
shprocess executes the attacker’s command within the sandbox’s context, bypassing the intended security restrictions. - The attacker gains unauthorized access to resources such as network connections, the filesystem, or cloud metadata services.
- The attacker escalates privileges and potentially compromises the entire system.
Impact
Successful exploitation of this vulnerability allows attackers to bypass the intended security restrictions imposed by the PraisonAI SubprocessSandbox, even in its strictest configuration. This could lead to privilege escalation, unauthorized access to sensitive data, and the potential compromise of the entire system. Specifically, an attacker could leverage this escape to access network resources, manipulate the filesystem, or extract sensitive information from cloud metadata services. The lack of effective sandboxing could have severe consequences for environments relying on PraisonAI for secure execution of untrusted code.
Recommendation
- Apply the suggested fix of using
shlex.split()andshell=Falsewhen callingsubprocess.run()to prevent shell command injection (reference: suggested fix code block). - Upgrade PraisonAI to a version beyond 4.5.96 to incorporate the patch for CVE-2026-34955 (reference: CVE-2026-34955).
- Deploy the provided Sigma rule to detect the execution of
shorbashwith the-coption, which is indicative of attempts to bypass command restrictions (reference: Sigma rule “Detect sh/bash Command Execution with -c Option”). - Implement a more comprehensive blocklist that includes
shandbashas standalone executables in addition to dangerous patterns (reference:sandbox_executor.py:179).
Detection coverage 2
Detect sh/bash Command Execution with -c Option
highDetects the execution of sh or bash with the -c option, which is often used to execute commands from a string, potentially bypassing security restrictions.
Detect PraisonAI SubprocessSandbox Escape Attempt
mediumDetects command line arguments indicative of an attempt to bypass PraisonAI's SubprocessSandbox by invoking sh/bash with a command string.
Detection queries are kept inside the platform. Get full rules →