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

CVE-2023-39659: LangChain vulnerable to arbitrary code execution

criticalCVSS 4.0 9.3 · 3.1 9.8GHSA-prgp-w7vf-ch62

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 langchain

Search 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

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