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

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

criticalCVSS 4.0 9.3 · 3.1 9.8GHSA-fj32-q626-pjjc

LangChain before 0.0.247 shipped CPALChain, a chain that ran Python derived from model output without validation, so a crafted prompt could run operating system commands. LangChain 0.0.247 removed the code from the main package and moved it to langchain-experimental, where it still carries no sandbox.

Published Aug 15, 2023 · Updated Sep 27, 2024 · Analysis Nov 2, 2026

What an attacker can do

The issue behind this advisory concerns the CPAL chain (causal program-aided language), built with from_univariate_prompt. The reporter placed a Python expression, print(exec("import os; os.system('dir')")), inside the natural-language question, and it ran with the privileges of the application. The issue page does not show the chain's internals, but the report implies that code derived from the model's output is executed with no validation against unbound Python or command execution.

An attacker needs only to get text to the chain: a chat input, a document the app summarizes, or any field that ends up in the prompt. 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 maintainer's position in the thread is that in-process Python sandboxing is an extremely difficult problem, so the project's answer is a removal plus warnings, not a filter.

Who is affected

The pip package langchain before 0.0.247. Applications that use CPALChain with input that untrusted people can influence are the exposed ones. After the move, the same class lives in the langchain-experimental package and has the same property. Check:

pip show langchain langchain-experimental

Then search your code for CPALChain.

langchain

Ecosystem
PyPI
Affected
>= 0, < 0.0.247
Fixed in
0.0.247
Check
pip show langchain

How to fix it

Upgrade langchain to 0.0.247 or later:

pip install --upgrade "langchain>=0.0.247"

Version 0.0.247 removes the affected code (pull requests 8092 and 8425). Anyone who still needs it must install langchain-experimental, which is not a fix: pull requests 9938 and 9936 added security notices to the class and to that package's README. The maintainer recommends running untrusted code in an external sandbox that you set up, such as a container with no secrets and no network.

How to tell if you were hit

Search your code for imports of CPALChain, from_univariate_prompt, or langchain-experimental in your dependency files. In logs of user questions and model output, look for Python syntax such as exec, os.system or __import__. On the host, check for unexpected child processes of the service that runs the chain.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

An issue in LangChain prior to v.0.0.247 allows a remote attacker to execute arbitrary code via the prompt parameter.

Questions

Does upgrading langchain make CPALChain safe?

Upgrading removes it from the main package. If you install langchain-experimental to keep using it, the chain is still unsandboxed and the project only added warnings.

Which component is affected?

The CPAL chain, created with from_univariate_prompt, according to the issue thread.

Which version fixes CVE-2023-38860?

langchain 0.0.247, which removed the affected code from the main package and moved it to langchain-experimental.

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