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

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

criticalCVSS 4.0 9.3 · 3.1 9.8GHSA-92j5-3459-qgp4

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-experimental

Then 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

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