NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · LangChain

CVE-2023-39631: Langchain vulnerable to arbitrary code execution via the evaluate function in the numexpr library

criticalCVSS 3.1 9.8GHSA-f73w-4m7g-ch9x

LangChain before 0.0.308 lets a remote attacker run code through LLMMathChain, which passes model-written expressions to numexpr's evaluate function. A crafted prompt can turn a math question into code execution on the host. Upgrade langchain to 0.0.308 and numexpr to 2.8.5 or later.

Published Sep 1, 2023 · Updated Feb 20, 2025 · Analysis Nov 2, 2026

What an attacker can do

LLMMathChain asks the model for a math expression, then its _evaluate_expression method in chains/llm_math/base.py strips the text and hands it to numexpr.evaluate. According to the issue reporter, numexpr's evaluate relies on Python's eval, so an expression written by the model can carry code. Setting global_dict to an empty dict and passing a local_dict did not block it. That explanation comes from the reporter and a bot reply, not a verified maintainer analysis.

The attacker only needs to influence the text sent to the chain, through a chat box, a retrieved document or any prompt injection route. The CVSS vector (AV:N, AC:L, PR:N, UI:N) scores 9.8. A hit gives code execution as the application's user, with its environment variables, API keys and files.

The advisory notes that numexpr is an optional dependency of LangChain, so the exposed deployments are those that installed it and use the math chain.

Who is affected

The pip package langchain before 0.0.308, and numexpr before 2.8.5. The CVE text names LangChain v0.0.245. You are exposed only if numexpr is installed and your code uses LLMMathChain or an agent tool built on it. Check:

pip show langchain numexpr

Then search your code for LLMMathChain.

langchain

Ecosystem
PyPI
Affected
< 0.0.308
Fixed in
0.0.308
Check
pip show langchain

numexpr

Ecosystem
PyPI
Affected
< 2.8.5
Fixed in
2.8.5
Check
pip show numexpr

How to fix it

Upgrade both packages:

pip install --upgrade "langchain>=0.0.308" "numexpr>=2.8.5"

The listed patched versions are langchain 0.0.308 and numexpr 2.8.5. The issue thread adds that numexpr 2.8.6 introduced input sanitization, and that LangChain later required numexpr 2.8.6 or newer and closed the issue as resolved in 0.0.325, so a newer release is the safer target. If you do not need the math chain, uninstall numexpr or remove the chain.

How to tell if you were hit

Search application logs and stored model outputs for expressions passed to the math chain that contain Python syntax such as __import__, os, subprocess or attribute access, instead of plain arithmetic. On the host, look for unexpected child processes from the Python service and outbound connections it should not make.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

An issue in LanChain-ai Langchain v.0.0.245 allows a remote attacker to execute arbitrary code via the evaluate function in the numexpr library.

Patches: Released in v.0.0.308. numexpr dependency is optional for langchain.

Credited to eyurtsev.

Questions

Is the bug in LangChain or in numexpr?

Both advisories are listed. LangChain's LLMMathChain feeds model output to numexpr.evaluate, and numexpr evaluates it with eval. The fixes are langchain 0.0.308 and numexpr 2.8.5.

Am I affected if I do not use LLMMathChain?

The sources describe the flaw through that chain. Check your code for other paths that pass untrusted text to numexpr.evaluate.

Is numexpr required by LangChain?

No. The advisory states numexpr is an optional dependency.

Is it exploited in the wild?

The sources do not say so, and the entry has no CISA catalog data.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More LangChain vulnerabilities

All LangChain entries