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

CVE-2026-40217: LiteLLM has a sandbox escape in custom-code guardrail

highCVSS 4.0 7.5 · 3.1 8.8GHSA-wxxx-gvqv-xp7p

LiteLLM's POST /guardrails/test_custom_code endpoint runs user-supplied Python in a hand-rolled sandbox that can be escaped, giving code execution in the proxy process, which runs as root in the default Docker image. A proxy-admin credential is needed. Fixed in litellm 1.83.10.

Published May 11, 2026 · Analysis Oct 27, 2026

What an attacker can do

The endpoint exists to test custom-code guardrails. It runs the submitted Python after filtering it with regex checks. The X41 write-up shows the filter can be beaten by building blocked names at runtime with string concatenation, then rewriting a generator's bytecode to reach the real builtins. The code then runs in the proxy process.

The attacker needs network access to the proxy's admin API and a proxy-admin credential in default configurations (X41's proof of concept used the master key). With that they get arbitrary code execution. In the default Docker image the process is root, so the result is full control of the container: provider API keys, the database connection string and every request passing through the gateway. Because the key is needed, the main risk is a leaked or over-shared admin key, or a lower-privileged path to it.

Who is affected

Affected: litellm from 1.81.8 up to but not including 1.83.10. Check:

pip show litellm

For Docker, check the image tag you run. X41 confirmed the issue on the main-latest image. Exposure is highest where the admin API is reachable beyond trusted hosts.

litellm

Ecosystem
PyPI
Affected
>= 1.81.8, < 1.83.10
Fixed in
1.83.10
Check
pip show litellm

How to fix it

Upgrade to litellm 1.83.10 (release v1.83.10-stable) or later:

pip install --upgrade litellm

The advisory text says the fix is in 1.83.11 while the package data lists 1.83.10 as patched; installing 1.83.11 or later satisfies both. The fix replaces the hand-rolled sandbox with RestrictedPython. If you cannot upgrade, block POST /guardrails/test_custom_code at the reverse proxy or API gateway. X41 also suggests limiting master key distribution, restricting network access to the management interface and running the container as an unprivileged user.

How to tell if you were hit

Search proxy and gateway access logs for POST requests to /guardrails/test_custom_code. Any call you did not expect is suspect, along with requests whose body holds string-concatenated names or generator and bytecode manipulation. Then check the container for new processes, files or outbound connections, and rotate provider keys and the master key if you find any.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Impact

The POST /guardrails/test_custom_code endpoint runs user-supplied Python inside a hand-rolled sandbox. The sandbox can be escaped using bytecode-level techniques, allowing arbitrary code execution in the proxy process — which runs as root in the default Docker image.

Reaching the endpoint requires a proxy-admin credential in default configurations.

Patches

Fixed in `1.83.11`. The hand-rolled sandbox has been replaced with RestrictedPython. Upgrade to 1.83.11 or later.

Workarounds

If upgrading is not immediately possible, block POST /guardrails/test_custom_code at your reverse proxy or API gateway.

References

Questions

Does exploiting this need authentication?

Yes. Reaching the endpoint requires a proxy-admin credential in default configurations. The X41 proof of concept used the master key.

Which versions are affected by CVE-2026-40217?

litellm 1.81.8 up to but not including 1.83.10, according to the package data.

What is the workaround?

Block POST /guardrails/test_custom_code at your reverse proxy or API gateway if you cannot upgrade right away.

Is it exploited in the wild?

No source says so, and it is not in CISA's KEV catalog. EPSS is relatively high at about 15 percent.

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

Coverage on the Beam blog

More LiteLLM vulnerabilities

All LiteLLM entries