When the AI Guardrail Runs Your Code: LiteLLM's Sandbox Escape (CVE-2026-40217)

LiteLLM, a popular gateway in front of LLMs, ran user-supplied Python inside a hand-built sandbox to test guardrails. Attackers escape it with bytecode tricks, get code execution as root, and turn a limited API key into full admin over the AI gateway. It's exploited and in CISA KEV. Here's how to secure your AI plumbing.

4 min readAdvanced

Executive summary. CVE-2026-40217 is an actively exploited sandbox escape in LiteLLM, the widely used proxy/gateway that sits in front of LLMs. Its POST /guardrails/test_custom_code endpoint runs user-supplied Python inside a hand-rolled sandbox built on deny-list/regex filtering. Bytecode-level techniques escape it, and in the default Docker image the process runs as root, so the result is remote code execution as root on the AI gateway. Google's threat intelligence group observed a threat actor use it to elevate a limited inference key ("Virtual Key") to full proxy-admin. CISA added it to KEV on 18 November 2026 (remediation due 2 December). Affected: >= 1.81.8, < 1.83.10; fix to 1.83.11 or later (the advisory text points to 1.83.11; the fix replaces the deny-list with RestrictedPython). This is a wake-up call for a new attack surface: the infrastructure that brokers your AI.

LiteLLM CVE-2026-40217 guardrail sandbox escape chain

What it is

Field Detail
CVE CVE-2026-40217 (GHSA-wxxx-gvqv-xp7p)
Product LiteLLM (LLM proxy/gateway)
Where POST /guardrails/test_custom_code — runs user Python in a sandbox
Type Sandbox escape → RCE (root in the default Docker image)
Impact Virtual Key → proxy-admin; full control of the gateway
Status Exploited (Google TIG); CISA KEV 18 Nov, due 2 Dec 2026
Affected / Fixed >= 1.81.8, < 1.83.10; fix 1.83.11+ (now uses RestrictedPython)

Why "a sandbox for user code" keeps failing

The endpoint exists to let teams test custom guardrail code. To do that safely it tried to sandbox arbitrary Python with a deny-list (blocking dangerous names via regex). That approach is fundamentally fragile:

  • Python is dynamically typed and highly reflective; there are countless ways to reach dangerous functionality indirectly.
  • Bytecode-level tricks sidestep source-level filters entirely.
  • A documented footgun: when exec() gets a globals dict without __builtins__, Python silently re-injects the full builtins — handing the "sandboxed" code everything back.

The lesson is old and keeps repeating: you cannot safely run untrusted code in a hand-rolled, deny-list sandbox. LiteLLM's fix swaps to RestrictedPython; the deeper answer is OS/container isolation for anything executing untrusted code.

The chain

  1. A caller with a limited Virtual Key reaches /guardrails/test_custom_code (reaching it needs a proxy-admin credential in default configs, but the exploit is used to gain that).
  2. Supplied Python escapes the sandbox via bytecode techniques.
  3. Code runs as root in the default Docker image, RCE on the gateway.
  4. The attacker elevates to proxy-admin, controlling every model, key and route the gateway brokers.

Why the AI gateway is a juicy target

A LLM gateway like LiteLLM concentrates risk:

  • It holds API keys to expensive model providers (OpenAI, Anthropic, cloud models) — directly monetisable if stolen.
  • It brokers every prompt and response, potentially sensitive data flowing through the organisation.
  • It often runs with broad network access to internal services and model backends.

Compromising it is compromising your AI supply line, and this is one of the first widely-exploited examples of attackers going after that layer specifically.

Remediation

Now

  1. Upgrade LiteLLM to 1.83.11 or later. The fix replaces the deny-list sandbox with RestrictedPython.
  2. Lock down the management interface. Restrict who can reach the admin/management endpoints (typically port 4000); don't expose them broadly.
  3. Segment LiteLLM so only trusted networks/services can reach it.

Harden

  1. Least-privilege Virtual Keys, rotate them, and review who holds admin.
  2. Don't run the gateway as root; constrain the container.
  3. Rotate provider API keys if you suspect exposure.

Detection and hunting

Signal Why
The LiteLLM process spawning shells or unexpected children Post-sandbox-escape RCE
Requests to /guardrails/test_custom_code you didn't make The exploit vector
Virtual Keys gaining admin / unexpected admin actions Privilege escalation
Unusual provider API usage spikes or new outbound destinations Stolen keys / exfiltration

Conclusion

CVE-2026-40217 is both a specific patch-now bug and a signpost: as organisations put gateways, guardrails and agents around their AI, that plumbing becomes attack surface, and the oldest mistakes (running untrusted code in a home-made sandbox, running as root, exposing admin interfaces) show up in new places. Patch LiteLLM, lock down its admin plane, and treat your AI infrastructure like the high-value target it is.

Do this now: upgrade LiteLLM to 1.83.11+, restrict the admin interface (port 4000) to trusted networks, stop running it as root, and rotate provider keys if exposed.

Related: Testing AI and LLM features in web apps and the Cairn AI-framework abuse.

Sources: GitHub Advisory GHSA-wxxx-gvqv-xp7p, Obsidian Security, Miggo, SentinelOne, DEV write-up. Confirm the fixed version against the GitHub advisory and the CISA KEV entry.

HackersRoot Research · Research team

The HackersRoot research team investigates attack techniques across AI systems, cloud and identity, and enterprise networks, then publishes the detections and hardening guidance that stop them.

More from HackersRoot →

Related research

AI & LLM Security

When the AI Pentester Works for the Attacker: Cairn, CL-STA-1238 and Autonomous Intrusions

Palo Alto Networks' Unit 42 reports that a China-nexus operator ran a modified copy of Cairn, an open-source AI penetration-testing framework, against 19 organisations in two weeks, with confirmed access at several. The techniques were familiar; the speed and scale for a tiny team were not. Here's what happened, what it means, and the defensive priorities that actually matter.