CVE-2023-29374: LangChain vulnerable to code injection
In LangChain through 0.0.131, LLMMathChain passes model-written Python to exec(), so prompt injection gives arbitrary code execution. The advisory data lists no patched version. The project later moved the chain to numexpr evaluation, so use a current release and treat any model-driven code execution as untrusted.
Published Apr 5, 2023 · Updated Sep 30, 2024 · Analysis Nov 2, 2026
What an attacker can do
LLMMathChain asks the model to turn a math question into Python and runs the result with exec(). A prompt that tells the model to emit other code makes the app run it. The original report, langchain issue 1026, says the llm_math and sql_database chains blindly execute whatever code the LLM returns. Its example concern was a crafted prompt, not a full exploit string.
An attacker therefore needs only to get text to a chain, for example through a chat front end, an API or a document the app summarises. The code then runs with the application's rights. That includes environment secrets, files, and network access. The EPSS percentile for this CVE is very high (0.985 in our data), which fits a flaw with a trivial recipe and wide exposure in early LangChain apps.
The fix was never a single patch. A quick pull request switched exec to eval, which its author called a quick patch and not a complete fix, and which is not a safe boundary either. It was closed in May 2023 with a note that the project was using numexpr now.
Who is affected
pip package langchain 0.0.131 and earlier, when the app uses LLMMathChain. Check:
pip show langchainThe advisory lists no patched version, so a version number alone does not tell you the code is safe. Confirm that your installed release evaluates math through numexpr and not exec by reading the chain's source.
langchain
- Ecosystem
- PyPI
- Affected
- <= 0.0.131
- Fixed in
- No patched version yet
- Check
pip show langchain
How to fix it
No patched version is named in the advisory. The issue thread and the closed pull request 1119 show the direction: the maintainers moved LLMMathChain to numexpr instead of running arbitrary Python. Upgrade to a current langchain release and check the chain source. Do not feed untrusted input to chains that execute generated code. Mitigations the thread discusses are running the code in a non-privileged container, a restricted runtime, or a WebAssembly sandbox. The thread notes that a container alone does not cover malicious input.
How to tell if you were hit
Search code for LLMMathChain and llm_math tool use, and check langchain pins in requirements files. In traces and logs, look for generated expressions that contain import, os, subprocess, open or exec instead of plain arithmetic. Check app hosts for unexpected child processes and outbound connections.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
In LangChain through 0.0.131, the LLMMathChain chain allows prompt injection attacks that can execute arbitrary code via the Python exec() method.
Questions
- Which langchain version fixes CVE-2023-29374?
The advisory names none. It lists everything through 0.0.131 as affected. The maintainers later moved the chain to numexpr, so use a current release and verify the chain source.
- Does switching exec to eval fix it?
No. The author of that change called it a quick patch, and the issue thread notes eval is still dangerous.
- Is this exploited in the wild?
No source says so, and it is not in CISA's KEV data. The EPSS percentile is high, so assume attackers know the pattern.
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 entriesCVE-2026-55443
LangChain: Path traversal and sandbox escape in LangChain file-search middleware and loaders
medium5.1Jun 16, 2026CVE-2026-45134
LangSmith SDK: Public prompt pull deserializes untrusted manifests without trust boundary warning
high7.1May 13, 2026CVE-2026-44843
LangChain vulnerable to unsafe deserialization of attacker-controlled objects through overly broad `load()` allowlists
high8.2May 8, 2026CVE-2026-40087
LangChain has incomplete f-string validation in prompt templates
medium5.3Apr 8, 2026CVE-2026-34070
LangChain Core has Path Traversal vulnerabilites in legacy `load_prompt` functions
high7.5Mar 27, 2026CVE-2026-27795
LangChain Community: redirect chaining can lead to SSRF bypass via RecursiveUrlLoader
medium4.1Feb 25, 2026
