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_commandandpost_run_commandconfigured 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_TOOLorAFTER_TOOLfire - 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 withshell=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.jsonagainst 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.

