Incident report

LangChain LLMMathChain Prompt Injection Arbitrary Python Code Execution

CVE-2023-29374 was one of the earliest high-profile LLM framework RCE CVEs, affecting LangChain's `LLMMathChain` (`numexpr` / Python `exec` fallback). Crafted natural-language prompts coerced the language model into returning arbitrary Python expressions rather than pure arithmetic, which the chain then executed directly on the host server. Attackers could read `/etc/passwd`, steal OpenAI API keys from `os.environ`, or establish reverse shells via a single chat prompt. Maintainers replaced unsafe Python evaluation with restricted AST expression parsing.

Incident record

Reported
Severity
Critical
Vector
Tool/MCP Abuse
Affected system type
LLM Math Evaluation Chains
Reference
CVE-2023-29374
Reference URI
https://nvd.nist.gov/vuln/detail/CVE-2023-29374

Inspect in Interactive Incidents Hub

Defensive lesson

Never pass model-generated math expressions into Python exec() or eval(); enforce strict numeric AST parsing for deterministic calculators.

Referenced techniques