Severity:

HIGH RISK

(7.3)

Code Injection in MetaGPT Tree-of-Thought Solver

CVE-2026-6110

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-74, CWE-94

Impact:

Remote Code Execution in Application Context

Severity:

HIGH RISK

(7.3)

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

MetaGPT up to version 0.8.1 contains a code injection vulnerability in the generate_thoughts function of the Tree-of-Thought (ToT) solver.

When untrusted input is incorporated into generated reasoning steps and later interpreted as code or executable instructions, a remote attacker can cause arbitrary code execution within the MetaGPT runtime.

Affected context

The vulnerability occurs in environments running MetaGPT (≤ 0.8.1) that use the Tree-of-Thought solver component and, directly or indirectly, treat generated thoughts as executable instructions or code.

Risk is elevated when external or user-supplied data is fed into the ToT pipeline, when generated thoughts can influence downstream code evaluation or tool invocation, and when there is no robust separation between model output and execution layers.

Any deployment that integrates MetaGPT into autonomous agents, workflows, or plugins that execute model-derived instructions is potentially affected.

Exploit preconditions

  • Attack surface: Remote, via any interface (API, UI, agent framework, or integration) that allows an attacker to influence prompts, context, or parameters feeding the Tree-of-Thought solver.
  • Required access: Ability to supply or control input text, tasks, or instructions consumed by the generate_thoughts function; no direct system-level access is required.
  • Trigger point: Execution or interpretation of generated thoughts as code, shell commands, or high-privilege tool calls within the MetaGPT agent workflow.
  • Why exploitation is possible: The ToT solver blends untrusted content into generated intermediate "thoughts" that are later handled in a way that allows execution or injection, without sufficient sanitization, validation, or isolation between reasoning output and executable actions.

Why this happens

The underlying issue is a failure to treat Tree-of-Thought outputs as untrusted data when they can influence executable behavior.

The generate_thoughts function likely constructs prompts or intermediate structures that mix attacker-controlled text with templates and then passes resulting "thoughts" into components that interpret them as executable code, commands, or structured instructions.

This maps to CWE-94: Improper Control of Generation of Code ('Code Injection') because model-generated strings derived from user input are allowed to shape or become executable logic, and to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') because special characters and control tokens are not safely neutralized before being consumed by downstream interpreters (e.g., shells, language runtimes, or tool dispatchers).

Conceptually, the bug class is "LLM/agent output injection": treating model reasoning steps as trusted code rather than as data that must be validated and sandboxed.

Potential impact

  • Remote attackers may cause execution of arbitrary code or commands within the MetaGPT application context.
  • Attackers could manipulate autonomous agents to perform unintended actions (e.g., file access, network calls, or data exfiltration) through injected thoughts.
  • Compromise of sensitive data handled by the agent, including prompts, context documents, API keys, or internal tooling outputs.
  • Lateral movement to other systems or services reachable from the MetaGPT host, depending on integration and permissions.
  • Integrity compromise of reasoning processes, leading to sabotaged analyses, corrupted outputs, or misleading automated decisions.

General mitigation guidance

Effective mitigation focuses on separating reasoning output from execution and treating all model-derived content as untrusted:

  • Introduce a strict boundary between generated thoughts and any execution layer; thoughts should be data only, never directly executed as code or commands.
  • Apply robust validation and allow-listing for any operations derived from ToT output (e.g., only permit a constrained set of tool calls or actions).
  • Normalize and sanitize special characters and control sequences in any text that might reach interpreters (shells, eval-like functions, templating engines).
  • Use structured, schema-validated instruction formats instead of free-form text when mapping reasoning steps to actions.
  • Run agent processes with least-privilege OS accounts and constrained capabilities so that, even if code injection occurs, the blast radius is reduced.
  • Prefer sandboxed execution environments for any dynamic behavior influenced by model output (e.g., containers, jailed interpreters, restricted tool runners).

How teams detect issues like this

Detection typically involves a mix of code-centric and behavior-centric approaches:

  • Static analysis: Search for patterns where ToT-generated strings or intermediate "thoughts" flow into dynamic execution points (e.g., eval, exec, shell invocation, templated code execution, or generic tool dispatchers) without strict validation.
  • Code review signals: Flag locations where MetaGPT outputs (especially from generate_thoughts) are treated as instructions, scripts, or command fragments instead of as plain data; examine adapter layers between thoughts and tools.
  • Policy enforcement: Establish internal guidelines that prohibit direct execution of LLM/agent output and enforce them via pre-commit hooks or CI policies.
  • Runtime monitoring: Instrument logging around action dispatch and command execution; look for anomalous or attacker-controlled patterns in commands derived from ToT reasoning, and correlate with external request origins.
  • Automated tools: Linting and SAST tools configured with rules for dynamic execution sinks and taint tracking from model/LLM inputs can help surface injection-prone flows early.

Sources

SourceLink
github.comgithub.com/FoundationAgents/MetaGPT/
github.comgithub.com/FoundationAgents/MetaGPT/issues/1933
github.comgithub.com/FoundationAgents/MetaGPT/pull/1946
vuldb.comvuldb.com/submit/791761
vuldb.comvuldb.com/vuln/356970
vuldb.comvuldb.com/vuln/356970/cti

Frequently asked

questions

Yes. If an attacker can supply or influence input to a MetaGPT deployment that uses the Tree-of-Thought solver, they can remotely craft payloads that propagate into generated thoughts and trigger code injection when those thoughts are acted upon.

The attacker typically only needs the ability to submit text or tasks to the system—through an API endpoint, web interface, chatbot integration, or any other channel that feeds into the Tree-of-Thought reasoning pipeline. No direct server or OS-level access is required.

The safest pattern is to eliminate any direct or implicit execution of model-generated content. Thoughts should be treated as untrusted data, mapped only to a constrained set of predefined actions or tool calls via strict allow-lists and schemas, with no use of eval-style constructs or free-form command assembly.

Design the system with clear trust boundaries: never execute raw model output, use structured protocols for actions, apply rigorous validation and sanitization, sandbox any dynamic behavior, and adopt security reviews focused specifically on LLM/agent output injection and dataflow from prompts to execution sinks.

Find out what's already
exploitable in your codebase.