/

CVE-2026-40111

Severity:

HIGH RISK

(8.8)

OS Command Injection in PraisonAIAgents Memory Hooks

CVE-2026-40111

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Code Execution

Severity:

HIGH RISK

(8.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

PraisonAIAgents' memory hooks executor previously passed user-controlled command strings directly into subprocess.run(..., shell=True) without sanitization, allowing shell metacharacters to be interpreted by /bin/sh.

If an attacker can influence hook configuration—especially the auto-triggered .praisonai/hooks.json lifecycle hooks—this can lead to silent, repeated remote code execution during normal agent operations.

Affected context

This vulnerability affects deployments of PraisonAIAgents that:

  • Use the memory hooks executor in praisonaiagents/memory/hooks.py
  • Allow dynamic configuration of hook commands via hooks configuration or .praisonai/hooks.json
  • Run agents that can be influenced through prompts or external inputs that may lead to file-write capabilities

The risk is highest where agents operate with access to the user's filesystem and lifecycle hooks are configured to run automatically.

Exploit preconditions

  • Attack surface:
  • Hook event types such as pre_run_command and post_run_command configured by the user
  • Lifecycle hooks defined in .praisonai/hooks.json (e.g., BEFORE_TOOL, AFTER_TOOL) that execute automatically
  • Required access:
  • Ability to modify hook configuration or .praisonai/hooks.json
  • In some scenarios, this may be obtained indirectly if an agent can be driven (e.g., via prompt injection) to write or overwrite that file
  • Trigger point:
  • Execution of the memory hook, where the configured command string is passed directly to subprocess.run(..., shell=True)
  • Why exploitation is possible:
  • The command string is treated as a shell command line, so shell metacharacters (;, &&, |, backticks, etc.) are interpreted by /bin/sh, allowing arbitrary command injection.

Why this happens

The core issue is the use of subprocess.run() with shell=True and a command string that is directly influenced by configuration without validation, escaping, or restriction.

This matches CWE-78: Improper Neutralization of Special Elements used in an OS Command, where untrusted input is concatenated into a shell command and executed.

Conceptually, the design conflates "configuration of a tool to run" with "free-form shell command execution," expanding the trust boundary to include data sources that may be indirectly attacker-controlled.

Potential impact

  • Execution of arbitrary OS commands with the privileges of the PraisonAIAgents process
  • Silent, repeated code execution each time lifecycle hooks like BEFORE_TOOL or AFTER_TOOL fire
  • Reading, modifying, or deleting local files accessible to the process
  • Credential theft from configuration files, environment variables, or local key stores
  • Lateral movement to other systems reachable from the compromised host
  • Use of the host as a pivot for further attacks or cryptomining

General mitigation guidance

Effective mitigation focuses on eliminating direct shell interpretation of configurable commands and tightening trust boundaries around configuration:

  • Prefer argument-list subprocess APIs (shell=False) and avoid passing untrusted input through a shell.
  • Where shell usage is unavoidable, constrain inputs to a small, validated set of commands or flags; reject or strictly filter shell metacharacters.
  • Introduce a command abstraction layer (e.g., named actions mapped to fixed command templates) instead of arbitrary user-supplied shell strings.
  • Treat configuration files (including .praisonai/hooks.json) as high-trust artifacts:
  • Restrict where they can be written from the application
  • Avoid allowing agent-driven logic to directly rewrite them
  • Run the agent with least-privilege OS accounts and restricted filesystem access so that, if command execution occurs, its reach is limited.
  • Consider separating execution environments for untrusted agent actions from the host system (e.g., containers, sandboxes).

How teams detect issues like this

Detection typically combines code-level checks with configuration review and runtime monitoring:

  • Static analysis and code scanning
  • Flag uses of subprocess.run, Popen, or similar APIs with shell=True, especially when arguments are derived from configuration files or user input.
  • Pattern-match locations where hook or lifecycle configuration values are passed into subprocess calls without validation.
  • Code review signals
  • Any feature that allows runtime "commands" or "hooks" from configuration should be scrutinized as potential command injection points.
  • Watch for designs where LLM/agent outputs can influence filesystem writes near configuration paths.
  • Configuration and policy enforcement
  • Validate .praisonai/hooks.json against a schema that restricts allowed commands or actions.
  • Implement organizational policies discouraging arbitrary shell hooks in production and enforcing review of hook configuration changes.
  • Runtime monitoring
  • Log and monitor subprocess executions triggered by hooks for unusual or high-risk commands.
  • Use host-based intrusion detection to flag anomalous shell activity originating from the PraisonAIAgents process.

Sources

SourceLink
github.comgithub.com/MervinPraison/PraisonAI/security/advisories/GHSA-v7px-3835-7gjx

Frequently asked

questions

It can be, depending on how the agent is exposed. If a remote party can influence hook configuration or drive the agent to write .praisonai/hooks.json (for example via prompt injection or remote inputs), they may achieve code execution without local access.

At minimum, the attacker must be able to cause changes to hook configurations or .praisonai/hooks.json. This could be direct filesystem access, or indirect control if the agent is allowed to persist configuration based on external instructions.

The safest pattern is to stop executing configurable shell strings altogether: remove shell=True, use argument-list subprocess calls, and restrict actions to predefined commands or adapters that do not expose raw shell invocation to configuration data.

Treat any path from external or model-controlled input to execution APIs as security-critical. Use safe subprocess patterns, apply strict validation to configuration-driven behaviors, constrain what agents can write to disk, and incorporate automated checks that flag shell-based execution of configurable strings during code review and CI.

Find out what's already
exploitable in your codebase.