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

CVE-2023-36258: langchain arbitrary code execution vulnerability

criticalCVSS 4.0 9.3 · 3.1 9.8GHSA-2qmj-7962-cjq8

A third advisory ID for the LangChain PALChain exec problem: a prompt that makes the model write malicious Python leads to arbitrary code execution in the host process. This ID lists langchain 0.0.247 as the fixed version, the release that removed PALChain from the package. Upgrade to 0.0.247 or later.

Published Jul 3, 2023 · Updated Nov 22, 2024 · Analysis Nov 2, 2026

What an attacker can do

The advisory text is short: an attacker can execute arbitrary code through PALChain, which calls Python's exec on generated code. The linked issue 5872 and its closing comment give the context. The maintainers released mitigations in 0.0.236, then moved PALChain into the langchain-experimental package and dropped it from langchain starting at 0.0.247. They also put security notices on the PAL and CPAL experimental chains.

What this means for a team: any service that sends user text to a PAL chain lets the user decide what Python the model writes. Prompt injection through retrieved content works as well. The code runs with the service's rights, so secrets in the environment and reachable internal systems are at risk.

This ID overlaps CVE-2023-36095 and CVE-2023-36188, which describe the same class of bug with different fixed versions. If you track them separately, one upgrade past 0.0.247 closes all three.

Who is affected

pip package langchain below 0.0.247, if your code builds a PALChain. After that release the class is not in langchain at all. Check:

pip list | grep -i langchain

If you installed langchain-experimental to keep PAL working, you are still running the risky pattern and should treat it as untrusted-code execution.

langchain

Ecosystem
PyPI
Affected
< 0.0.247
Fixed in
0.0.247
Check
pip show langchain

How to fix it

Upgrade to langchain 0.0.247 or later. Release 0.0.236 had earlier mitigations, but this advisory's fixed version is 0.0.247.

pip install --upgrade "langchain>=0.0.247"

If you keep PALChain through langchain-experimental, follow its warning and run the generated code in a sandbox outside your process, such as a locked-down container.

How to tell if you were hit

Grep your code base and dependency lock files for PALChain and langchain versions below 0.0.247. In traces of LLM calls, look for generated code that imports os or subprocess, or opens files and sockets. Check service hosts for odd child processes or outbound connections.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

An issue in langchain allows an attacker to execute arbitrary code via the PALChain in the python exec method.

Questions

Why does CVE-2023-36258 name 0.0.247 while CVE-2023-36095 names 0.0.236?

The 0.0.236 release added ast checks and a time limit. Release 0.0.247 removed PALChain from langchain entirely. The advisories picked different points on the same fix history.

Do I have to leave PALChain behind?

Not necessarily, but its new home, langchain-experimental, warns that in-process Python sandboxing is hard. Use external sandboxing or avoid it for untrusted input.

Is this exploited in the wild?

No source says so. The advisory is not in CISA's KEV 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