/

CVE-2026-40156

Severity:

HIGH RISK

(7.8)

Arbitrary Code Execution via Insecure Auto-Loading

CVE-2026-40156

Analyzed

Vulnerability type

Category:

Arbitrary Code Execution via Insecure Auto-Loading

CWE:

CWE-94, CWE-426, CWE-829

Impact:

Arbitrary Code Execution

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 versions prior to 4.5.128 automatically discover and execute a tools.py file from the current working directory using dynamic import mechanisms, without explicit user intent or sandboxing.

If an attacker can place a malicious tools.py in a directory where PraisonAI is run—such as a developer machine or CI/CD workspace—they can cause arbitrary code execution as soon as PraisonAI starts, before any agent logic or configuration is processed.

Affected context

This vulnerability affects PraisonAI environments where:

  • The application is started in directories that may contain user-supplied or third-party project files.
  • PraisonAI is expected to treat configuration (e.g., YAML, prompts, project assets) as non-executable content.
  • The tools.py auto-discovery mechanism is active and implicitly scans the current working directory.

It is especially relevant in shared workspaces, cloned repositories, CI/CD pipelines, and automation scripts where the current working directory is not tightly controlled and may include files from untrusted or partially trusted sources.

Exploit preconditions

  • Attack surface: Local execution context of PraisonAI (developer machine, build agent, CI runner, or automation host).
  • Required access: Ability to create, modify, or drop a file named tools.py into the directory from which PraisonAI will be executed (e.g., via poisoned repository, compromised dependency, or write access to a shared workspace).
  • Trigger point: Simply launching PraisonAI from the affected directory; the application automatically imports and executes tools.py at startup using importlib.util.spec_from_file_location and spec.loader.exec_module().
  • Why exploitation is possible: The design assumes any tools.py present in the current working directory is trusted, and executes its module-level code without user confirmation, validation, or sandboxing, effectively treating arbitrary project files as trusted code.

Why this happens

The underlying issue is a combination of insecure dynamic code loading and misplaced trust in the current working directory as a source of executable modules.

PraisonAI's auto-discovery mechanism unconditionally looks for a tools.py file and loads it using Python's dynamic import facilities:

  • It constructs a module spec from a file path (importlib.util.spec_from_file_location).
  • It immediately executes the module's top-level code with spec.loader.exec_module().

This behavior maps primarily to CWE-94: Improper Control of Generation of Code, as arbitrary, user-controlled Python code is executed without restriction. It is closely related to:

  • CWE-426: Untrusted Search Path, because the current working directory is treated as a trusted code source.
  • CWE-829: Inclusion of Functionality from Untrusted Control Sphere, since executable behavior is sourced from files residing in a user-controlled project folder.

Conceptually, the pattern is: "Treat any file with a special name in the working directory as executable plugin code and run it automatically," which breaks the intended boundary between configuration/content and code.

Potential impact

  • Arbitrary code execution on the host where PraisonAI runs (developer workstation, CI agent, or server).
  • Compromise of CI/CD pipelines, including theft of secrets, tokens, or environment variables.
  • Installation of backdoors or persistence mechanisms on development or build machines.
  • Tampering with PraisonAI behavior, such as altering agent tools, exfiltrating data, or manipulating model prompts and outputs.
  • Lateral movement within a build or deployment environment if additional credentials or network paths are accessible.

General mitigation guidance

Effective mitigation focuses on tightening the trust boundaries around code loading and eliminating implicit execution behaviors:

  • Disable implicit auto-loading from the current working directory:
  • Avoid scanning arbitrary directories for special filenames (like tools.py) and executing them automatically.
  • Require explicit registration of plugins or tools in configuration files or via command-line flags.
  • Introduce an explicit, trusted plugins directory:
  • Load dynamic tools only from a well-defined, controlled location (e.g., a dedicated plugins folder with restricted write access).
  • Ensure that only vetted, version-controlled modules are allowed in that directory.
  • Separate configuration from code:
  • Treat project-level configuration files (YAML, JSON, prompts) as data only and ensure they cannot implicitly introduce executable modules.
  • Avoid design patterns where "dropping a file with a special name" enables execution.
  • Validate and constrain dynamic imports:
  • Use allowlists of permitted modules or entry points.
  • Avoid executing module-level code for untrusted extensions; instead, inspect modules for specific, well-defined symbols (e.g., tool definitions) and handle them defensively.
  • Harden execution environments:
  • Run PraisonAI with least privilege, minimizing filesystem, network, and secret access.
  • Consider using virtual environments, containers, or sandbox mechanisms to limit the blast radius if untrusted code runs.

How teams detect issues like this

Detection approaches can combine code-centric and environment-centric techniques:

  • Static analysis and code review:
  • Flag uses of importlib.util.spec_from_file_location, exec_module, or similar dynamic loading patterns that target file paths in the current working directory.
  • Review any auto-discovery logic that scans for special filenames (e.g., tools.py) and automatically executes them.
  • Watch for patterns where configuration directories are also treated as code repositories.
  • Policy and configuration checks:
  • Enforce internal guidelines that disallow implicit code execution from CWD or project roots without explicit opt-in.
  • Use PR templates and review checklists that call out plugin/discovery mechanisms for additional scrutiny.
  • Runtime monitoring:
  • Log module import activity for PraisonAI, especially imports originating from the working directory or unexpected paths.
  • In CI/CD environments, alert on unexpected file creation of tools.py or similar "magic" plugin filenames.
  • Automated tooling:
  • Integrate SAST tools that can detect untrusted search paths and dynamic code execution flows (CWE-94, CWE-426, CWE-829).
  • Use filesystem integrity or policy-as-code tools (e.g., CI security scanners) to block suspicious files being introduced into build workspaces.

Sources

SourceLink
github.comgithub.com/MervinPraison/PraisonAI/security/advisories/GHSA-2g3w-cpc4-chr4

Frequently asked

questions

It is not directly remotely exploitable in the pure network sense, but remote attackers may exploit it indirectly by getting a malicious tools.py into a repository, shared folder, or CI workspace that a user later runs PraisonAI from. Once PraisonAI starts in that directory, the malicious code executes automatically.

An attacker must be able to place or modify a tools.py file in the directory where PraisonAI is executed. This can stem from write access to a shared project folder, compromising a Git repository, injecting files through a supply-chain attack, or influencing artifacts that end up in CI/CD workspaces.

The safest pattern is to remove implicit, name-based auto-loading from the current working directory and replace it with explicit, opt-in plugin registration from a trusted location. Dynamic tools should be loaded only from directories under strict control, with minimal privileges and clear configuration.

Future designs should treat the current working directory as untrusted by default, avoid executing code merely because a file exists with a special name, and enforce a clear separation between configuration/data and executable code. Applying principles like explicit opt-in, least privilege, restricted search paths, and defensive validation of dynamic imports helps prevent this class of vulnerability.

Find out what's already
exploitable in your codebase.