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

CVE-2023-36188: langchain vulnerable to arbitrary code execution

criticalCVSS 3.1 9.8GHSA-57fc-8q82-gfp3

LangChain's PALChain passes model-written Python to exec, so a remote attacker who controls the prompt can run arbitrary code. This entry, CVE-2023-36188, is fixed in langchain 0.0.247, where the vulnerable code was removed. It is a second, later fix for the same PALChain problem as CVE-2023-36095, which was patched in 0.0.236. Upgrade to 0.0.247 or later.

Published Jul 6, 2023 · Updated Jul 6, 2026 · Analysis Nov 2, 2026

What an attacker can do

PALChain asks an LLM for a Python program that solves the user's question, then runs it with exec inside the application. The issue reported as langchain issue 5872 shows a prompt that asks for import os and os.system('ls') alongside a math problem, and the chain runs it.

The flaw is CWE-74 injection into a downstream interpreter. The model's output is untrusted because the prompt is. Any app that lets outside users, or documents and web pages they influence, reach a PAL chain gives them code execution with the app's own privileges. That means API keys in environment variables, local files, cloud credentials and network access from the host.

The earlier 0.0.236 fix added ast-based checks. This advisory's fix range runs to 0.0.247, the release that removed the chain from langchain, so checks alone were not treated as enough. The reporter is credited as cookesan.

Who is affected

pip package langchain before 0.0.247 when the app builds a PALChain and runs it on untrusted input. Check what is installed:

pip show langchain

If you moved to langchain-experimental, the same class lives there and carries a security warning, so check that package too.

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:

pip install --upgrade "langchain>=0.0.247"

PAL support was moved out of the main package into langchain-experimental. If you install that package to keep using PALChain, the maintainers warn that sandboxing Python in-process is hard. Run generated code in an external sandbox, and avoid passing untrusted text to the chain.

How to tell if you were hit

Search your code for PALChain, from_math_prompt and from_colored_object_prompt. In LLM traces and logs, look for generated programs containing import, os.system, subprocess or file and socket calls. Check the service host for unexpected child processes and outbound connections. Where coding agents on developer machines run this stack, Beam's record of agent shell commands and file access can show what executed.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

An issue in langchain allows a remote attacker to execute arbitrary code via the PALChain parameter in the Python exec method.

Credited to cookesan.

Questions

How does CVE-2023-36188 differ from CVE-2023-36095?

Both concern PALChain and exec. CVE-2023-36095 lists 0.0.236 as its fix, which added ast checks. CVE-2023-36188 lists 0.0.247, where the vulnerable code was removed from langchain.

Is langchain 0.0.240 affected?

Yes. Any version before 0.0.247 is in the affected range for this advisory, even though 0.0.236 fixed the related CVE-2023-36095 checks.

Is it exploited in the wild?

No source says so. It is not in CISA's KEV data. A public issue contains a working prompt, so exploitation is easy if the chain is exposed.

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