/

CVE-2026-40287

Severity:

HIGH RISK

(8.4)

Arbitrary Code Execution via Insecure Dynamic Loading

CVE-2026-40287

Analyzed

Vulnerability type

Category:

Arbitrary Code Execution via Insecure Dynamic Loading

CWE:

CWE-94, CWE-426

Impact:

Remote Code Execution in Host Environment

Severity:

HIGH RISK

(8.4)

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 versions 4.5.138 and below automatically import a local tools.py file from the current working directory without any validation or sandboxing, enabling arbitrary Python code execution.

If an attacker can place a malicious tools.py alongside a PraisonAI project or in any directory where PraisonAI is launched, they can execute code on the host system with the privileges of the PraisonAI process.

Affected context

This vulnerability affects PraisonAI deployments and workflows where:

  • The application is started in directories that are writable by untrusted users or processes
  • Users work with cloned repositories, shared projects, or collaborative workspaces
  • The startup routines in call.py, tool_resolver.py, or CLI entrypoints automatically search for and import a local ./tools.py file

In such contexts, PraisonAI treats any tools.py present in the working directory as trusted code and executes it during initialization.

Exploit preconditions

  • Attack surface: Local file system / project workspace where PraisonAI is launched
  • Required access: Ability to create or modify a tools.py file in the current working directory (e.g., through a shared repo, writable folder, or compromised workspace)
  • Trigger point: Launching PraisonAI (CLI or programmatic) in a directory containing the attacker's tools.py
  • Why exploitation is possible: The tool-loading logic blindly imports ./tools.py at startup without integrity checks, user prompts, or execution sandboxing, causing Python to execute arbitrary module-level code.

Why this happens

The core issue is the implicit trust placed in executable code discovered in the current working directory.

Components such as import_tools_from_file() in call.py and _load_local_tools() in tool_resolver.py implement a pattern where ./tools.py is automatically imported as a module whenever PraisonAI starts.

This maps to CWE-94: Improper Control of Generation of Code ('Code Injection') and is closely related to CWE-426: Untrusted Search Path, because untrusted local paths are treated as authoritative sources for executable code.

Instead of loading declarative tool configurations or validating source files, the implementation directly executes whatever Python code resides in tools.py, effectively expanding the trusted computing base to any file in the working directory.

Potential impact

  • Execution of arbitrary Python code with the privileges of the PraisonAI process
  • Full compromise of the host environment where PraisonAI runs
  • Exfiltration or tampering of data, API keys, and credentials accessible to PraisonAI
  • Installation of backdoors or persistence mechanisms on the host system
  • Lateral movement into other systems reachable from the compromised environment
  • Manipulation of agent behavior, results, and downstream automation pipelines

General mitigation guidance

Mitigation patterns for this class of vulnerability focus on removing implicit trust in local executable content and constraining dynamic loading:

  • Replace automatic module imports from the current working directory with explicit, user-controlled configuration of tool locations.
  • Prefer declarative tool definitions (e.g., JSON, YAML, or restricted schemas) over importing arbitrary Python modules, and validate these definitions before use.
  • If dynamic imports are required, restrict search paths to trusted, application-controlled directories outside user-writable locations.
  • Introduce allowlists for permitted tool modules or entrypoints, and fail closed when encountering unexpected files.
  • Run PraisonAI with least-privilege OS accounts and, where possible, within containers or sandboxes to limit damage from any loaded code.
  • Document safe operational practices: avoid starting PraisonAI in untrusted or shared directories, and keep workspaces under controlled ownership and permissions.

How teams detect issues like this

Detection typically relies on both code-level and operational controls:

  • Static analysis and code review:
  • Flag uses of importlib, __import__, or exec that reference paths derived from working directories or user-controlled input.
  • Identify logic that automatically imports tools.py or similarly named modules without validation.
  • Enforce review policies around any dynamic loading or plugin mechanisms.
  • Configuration and policy enforcement:
  • Define secure coding guidelines that prohibit automatic imports from the current working directory.
  • Use CI policies or linters to prevent introduction of new auto-loading paths in tooling or agents.
  • Runtime and monitoring:
  • Monitor for unexpected execution of user-space modules from workspace directories.
  • Log and review module import paths during PraisonAI startup to detect loading from untrusted locations.
  • Automated security tools (SAST and configuration scanners) can be configured with rules that specifically target untrusted search paths and unsafe dynamic imports.

Sources

SourceLink
github.comgithub.com/MervinPraison/PraisonAI/security/advisories/GHSA-g985-wjh9-qxxc

Frequently asked

questions

It can be, depending on how PraisonAI is used. If an attacker can influence the contents of the directory where PraisonAI is launched (for example via a cloned repository, shared project, or synced workspace), they can effectively achieve remote code execution when a victim runs PraisonAI there.

The attacker needs the ability to create or modify a tools.py file in the current working directory of the PraisonAI process. This can occur through write permissions in shared folders, malicious templates or starter projects, or compromised repositories.

The safest pattern is to remove automatic imports from user-writable directories, require explicit configuration of trusted tool sources, and restrict dynamic loading to known, controlled locations. Where possible, favor declarative tool descriptions over executable Python modules.

Establish secure plugin and extension design patterns: avoid trusting the working directory, perform strict validation of any dynamically loaded resources, review all dynamic import mechanisms, and integrate static analysis rules that flag untrusted search paths and unsafe dynamic code execution.

Find out what's already
exploitable in your codebase.