CVE-2023-38896: LangChain vulnerable to arbitrary code execution
LangChain before 0.0.236 lets a remote attacker run code through PALChain, built with from_math_prompt or from_colored_object_prompt. The chain has a model write Python from the user's text and runs it. Version 0.0.236 adds mitigations. PALChain was later moved to langchain-experimental.
Published Aug 15, 2023 · Updated Sep 27, 2024 · Analysis Nov 2, 2026
What an attacker can do
PALChain (program-aided language) asks the LLM to write Python for the user's question, then executes it. Because the question is user-controlled, so is the code. In issue 5872 the reporter asked the chain to import os, call os.system('ls') and add 1+1, and the shell command ran. The same holds for from_colored_object_prompt, and a maintainer agreed that the whole chain is affected.
The attacker needs only to reach the prompt, through a chat form, an API or content the application feeds to the model. The CVSS vector (AV:N, AC:L, PR:N, UI:N) scores 9.8. A hit gives command execution as the application's user, with its secrets, files and network reach.
The 0.0.236 mitigations came from pull request 6003, merged as 7870. The issue page does not describe the checks. The maintainer stressed that in-process Python sandboxing is famously hard, so treat the fix as hardening, not a guarantee. A later bypass of this very filter exists: see CVE-2023-44467.
Who is affected
The pip package langchain before 0.0.236. Applications that call PALChain.from_math_prompt or PALChain.from_colored_object_prompt with untrusted input are exposed. Since 0.0.247 the class lives in langchain-experimental. Check:
pip show langchain langchain-experimentalThen search your code for PALChain.
langchain
- Ecosystem
- PyPI
- Affected
- < 0.0.236
- Fixed in
- 0.0.236
- Check
pip show langchain
How to fix it
Upgrade langchain to 0.0.236 or later:
pip install --upgrade "langchain>=0.0.236"From 0.0.247, PALChain was removed from langchain and moved to langchain-experimental, with security notices. The issue thread recommends running generated code in an external sandbox that you set up, since an in-process filter is not durable. The sources list no other workaround.
How to tell if you were hit
Search logs of user questions and generated code for os, subprocess, system, __import__ and similar calls inside code the PAL chain produced. Check your code for PALChain uses. 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 Harrison Chase langchain before version 0.0.236 allows a remote attacker to execute arbitrary code via the from_math_prompt and from_colored_object_prompt functions.
Questions
- Which functions are affected?
PALChain.from_math_prompt and PALChain.from_colored_object_prompt, per the advisory text.
- Is 0.0.236 enough?
It adds mitigations, but a keyword-style filter was later bypassed. See the entry for CVE-2023-44467. Sandbox the generated code if untrusted users can reach the chain.
- Where did PALChain go?
Starting with 0.0.247 it was moved to the langchain-experimental package.
- Is it exploited in the wild?
The sources do not say so, and the entry has no CISA catalog data.
References
Read for this analysis:
- https://nvd.nist.gov/vuln/detail/CVE-2023-38896
- https://github.com/hwchase17/langchain/pull/6003
- https://twitter.com/llm_sec/status/1668711587287375876
- https://github.com/langchain-ai/langchain/commit/8ba9835b925473655914f63822775679e03ea137
- https://github.com/langchain-ai/langchain/commit/e294ba475a355feb95003ed8f1a2b99942509a9e
- https://github.com/pypa/advisory-database/tree/main/vulns/langchain/PYSEC-2023-146.yaml
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
