/

CVE-2026-39891

Severity:

HIGH RISK

(8.8)

Template Injection / Code Injection in PraisonAI

CVE-2026-39891

Analyzed

Vulnerability type

Category:

Template Injection / Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution within the Application Context

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

PraisonAI's agent-centric tooling pipeline previously rendered user-controlled content as templates, allowing template expressions within user input to be evaluated instead of treated as plain text.

When agent.start() input is passed directly into tools like acp_create_file without appropriate escaping, this behavior can enable arbitrary template execution and potentially lead to code execution under the agent's runtime context.

Affected context

This vulnerability affects PraisonAI deployments using multi-agent teams where:

  • Agents use create_agent_centric_tools() to obtain tools such as acp_create_file.
  • Tool implementations process file content or similar data via template rendering engines.
  • Raw user input from agent.start() (or similarly untrusted sources) is passed directly into templates.

The issue is most relevant in scenarios where agents accept free-form user prompts or external content and then feed this content into tools that render templates for file generation, command construction, or other dynamic operations.

Exploit preconditions

  • Attack surface: User input into agents, including prompts and instructions consumed by agent.start().
  • Required access: Ability to supply or influence agent input (e.g., interactive user, API client, or upstream system feeding text to the agent).
  • Trigger point: Invocation of tools returned by create_agent_centric_tools() that render templates with the attacker-controlled content, such as acp_create_file.
  • Why exploitation is possible: The template renderer interprets special syntax in user-controlled content as executable template expressions instead of plain text, and the inputs are not escaped, sanitized, or constrained before rendering.

Why this happens

The root cause is the unsafe mixing of untrusted user-controlled content with a template rendering engine that has access to dynamic expression evaluation and possibly code execution.

In create_agent_centric_tools(), tools like acp_create_file treat content as a template and call a renderer that interprets embedded expressions.

Because input from agent.start() is passed directly into this renderer without escaping or restricting expression capabilities, attackers can introduce template syntax that gets evaluated at render time.

This is an instance of CWE-94: Improper Control of Generation of Code ('Code Injection'), expressed through template injection: user input controls the evaluated logic inside the template, rather than being handled as inert data.

Potential impact

  • Execution of template expressions that can read or manipulate internal agent state.
  • Potential arbitrary code execution within the agent's runtime environment, depending on the template engine's capabilities.
  • Unauthorized file creation or modification via tools like acp_create_file using attacker-controlled content and paths.
  • Leakage of sensitive data accessible to the agent (API keys, configuration values, intermediate tool results).
  • Manipulation of downstream tools or systems that consume generated files or rendered outputs.

General mitigation guidance

Effective mitigation focuses on treating user input as data, not as executable template logic:

  • Use escaping by default for any user-controlled content rendered in templates, ensuring special template syntax is treated as literal text.
  • Prefer data-binding and parameterized template variables over directly concatenating or injecting raw user input into template expressions.
  • Restrict template engines to non-expressive or sandboxed modes that disallow arbitrary code execution and limit available functions and objects.
  • Introduce clear trust boundaries: separate trusted templates (defined by developers) from untrusted content (from users, external systems, or other agents).
  • Apply the principle of least privilege to agent runtime environments so that even if a template is abused, the scope of damage is constrained (limited filesystem access, restricted environment variables, scoped credentials).

How teams detect issues like this

Detection typically combines code-level analysis with behavioral monitoring:

  • Static analysis and code review:
  • Search for calls to template rendering APIs where arguments include user or agent input originating from agent.start() or other untrusted sources.
  • Flag patterns where tools built by create_agent_centric_tools() render content that is not explicitly escaped or sanitized.
  • Review any tooling that generates files, commands, or scripts from user-driven templates.
  • Policy and linting rules:
  • Enforce project-wide policies that require escaping of untrusted content before template rendering.
  • Add CI checks that prohibit use of highly expressive or unrestricted template evaluators in user-facing paths.
  • Runtime monitoring:
  • Log and inspect template rendering inputs for suspicious expression patterns.
  • Enable anomaly detection around file creation, unexpected template variables, or unusual tool invocations triggered by user prompts.

Sources

SourceLink
github.comgithub.com/MervinPraison/PraisonAI/security/advisories/GHSA-hwg5-x759-7wjg

Frequently asked

questions

Yes, if PraisonAI is exposed via a remote interface (e.g., web API, chat interface, or service endpoint) where remote users can supply input to agent.start(), they can potentially exploit the template rendering behavior remotely.

The attacker needs the ability to provide or influence the input consumed by agent.start() or other agent entrypoints that flow into tools returned by create_agent_centric_tools(). No direct filesystem or shell access is required; access to the agent-facing interface may be sufficient.

Refactor tool implementations so that any user-controlled content is treated as literal data: escape untrusted input before rendering, use parameterized templates instead of concatenation, and limit template engines to non-expressive or sandboxed modes that cannot execute arbitrary code.

Design agent tooling with strict separation between templates and data, enforce input validation and escaping for all untrusted sources, and adopt coding standards that prohibit passing raw user input into template or code-generation APIs. Integrate static analysis and code review checklists specifically targeting template injection and code injection patterns.

Find out what's already
exploitable in your codebase.