CVE-2023-39659: LangChain vulnerable to arbitrary code execution
LangChain before 0.0.325 lets a remote attacker run code through PythonAstREPLTool._run, which executes whatever Python the agent passes in without checks. A crafted prompt can make the model emit os.system calls. The fix in 0.0.325 deprecates the Python REPL tooling in langchain.
Published Aug 15, 2023 · Updated Sep 27, 2024 · Analysis Nov 2, 2026
What an attacker can do
In agents that use PythonAstREPLTool, the model's Action Input goes straight to the tool's _run method, which runs it with no checking. The reporter in issue 7700 showed code such as __import__('os').system('ls') executing, and said the same happens with PythonREPLTool in a Python agent. A malicious prompt is enough to get the model to produce that Action Input.
When the prompt is exposed to users, for example a chat front end on a server, any user can attempt it. The CVSS vector (AV:N, AC:L, PR:N, UI:N) scores 9.8. Success yields command execution as the application's user, with its environment variables, keys, files and network.
The maintainers did not add a sanitizer. Pull request 12427 deprecates the tooling from langchain, as the thread describes, and the issue closed when 0.0.325 shipped. Pull request 5640, an earlier attempt, had not been merged when the thread discussed it.
Who is affected
The pip package langchain before 0.0.325. Agents that include PythonAstREPLTool or PythonREPLTool and take input from untrusted users are exposed. Check:
pip show langchainSearch your code for PythonAstREPLTool, PythonREPLTool and create_pandas_dataframe_agent, which may wrap such a tool.
langchain
- Ecosystem
- PyPI
- Affected
- < 0.0.325
- Fixed in
- 0.0.325
- Check
pip show langchain
How to fix it
Upgrade langchain to 0.0.325 or later:
pip install --upgrade "langchain>=0.0.325"The fix deprecates the Python REPL tools in langchain. If you still need an agent that executes code, run it in an isolated container with no secrets and no network, because the tool itself offers no protection. The sources list no other workaround.
How to tell if you were hit
Search agent traces for Action Input values with __import__, os.system, subprocess or open calls going to a Python REPL tool. Look for unexpected child processes from the service hosting the agent, and for outbound connections it should not make. Review any prompts that tell the agent to run shell commands.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
An issue in langchain langchain-ai before version 0.0.325 allows a remote attacker to execute arbitrary code via a crafted script to the PythonAstREPLTool._run component.
Credited to eyurtsev.
Questions
- Is PythonREPLTool affected as well?
The issue reporter says the same problem appeared with PythonREPLTool in a Python agent.
- What did 0.0.325 change?
Per the issue thread, pull request 12427 deprecates the affected tooling in langchain. It does not add a sanitizer.
- Does the attacker need an account?
No privileges are needed in the CVSS vector. They need to reach a prompt that feeds an agent with this tool.
- 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://github.com/langchain-ai/langchain/issues/7700
- https://github.com/advisories/GHSA-prgp-w7vf-ch62
- https://nvd.nist.gov/vuln/detail/CVE-2023-39659
- https://github.com/langchain-ai/langchain/pull/5640
- https://github.com/langchain-ai/langchain/pull/12427
- https://github.com/langchain-ai/langchain/commit/cadfce295f8a33828fc635c2e5ea28b883e5c992
- https://github.com/langchain-ai/langchain/releases/tag/v0.0.325
- https://github.com/pypa/advisory-database/tree/main/vulns/langchain/PYSEC-2023-147.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
