LiteLLM guardrail escape

A technical case study of CVE-2026-40217: detection, containment, and remediation of a sandbox escape in an AI gateway.

Summary

In November 2026, a 600-employee AI platform provider operating LiteLLM 1.82.x as its model gateway was targeted using CVE-2026-40217. An administrator credential that had been committed to a public repository was used from an unfamiliar network to invoke the guardrail test endpoint. Our system detected the anomalous credential use and the subsequent process activity, denied egress, isolated the workload, and revoked the credential within 21 seconds. No command-and-control connection was established and no provider credential was exfiltrated.

  • CVE: CVE-2026-40217
  • CVSS: 5.9, reflecting the requirement for a proxy administrator credential
  • Affected: LiteLLM 1.81.8 through 1.83.9
  • Fixed: 1.83.11, which replaces the hand-rolled sandbox with RestrictedPython
  • CISA KEV: added 18 November 2026
  • Time to contain: 21 seconds

Vulnerability overview

CVE-2026-40217 is a sandbox escape in the LiteLLM guardrail testing interface. The endpoint POST /guardrails/test_custom_code executes administrator-supplied Python so that guardrail logic can be tested before deployment. The sandbox applied source-level filtering but did not isolate the runtime; a bytecode-level payload could construct a function object outside the filter and execute it within the proxy process. In the default container image, that process runs as the root user.

POST /guardrails/test_custom_code HTTP/1.1
Host: llm-gateway.internal.example.com
Authorization: Bearer sk-admin-...
Content-Type: application/json

{"code": "<bytecode payload>"}

The vulnerability requires a proxy administrator credential in the default configuration, which is reflected in the base score. The material risk is post-authentication: the proxy holds provider API keys, mediates all model traffic, and enforces guardrail policy. Code execution at that privilege level places the confidentiality and integrity of the gateway and the model traffic it handles at risk.

Detection

Our system collects gateway access logs, Kubernetes audit events, cloud identity logs, endpoint telemetry, DNS queries, and egress flow records. The administrator key in use was 214 days old and had previously been used only from the build network. At 03:11:52 it authenticated from an autonomous system not present in the environment baseline and called the guardrail test endpoint, which had no prior use in 90 days of telemetry.

admin_key.first_seen_hours < 24
and http.path == "/guardrails/test_custom_code"
and source.asn not in baseline

Endpoint telemetry recorded the Python proxy process spawning /bin/sh thirteen seconds later. The gateway does not normally spawn shell processes. A DNS query to an unfamiliar domain followed immediately.

Response timeline

  1. 03:11:48The administrator key lists models from 45.148.x.x. First contact.
  2. 03:11:52Key used from a new network. Source and key age flagged against baseline.
  3. 03:12:04POST to /guardrails/test_custom_code with a bytecode payload.
  4. 03:12:05Sandbox escape. Proxy process opens /bin/sh as uid 0.
  5. 03:12:06Environment variables read. DNS query to an unfamiliar domain.
  6. 03:12:09Egress denied. Workload isolated from the network.
  7. 03:12:11Administrator key revoked. Provider credentials queued for rotation.
  8. 03:12:31On-call engineer paged with the evidence package. Incident ticket opened.

Containment and recovery

Initial response actions were reversible and automated: egress to the destination was denied, the workload was isolated, and the administrator key was revoked. Remediation of the gateway image required operator approval because it changed a production deployment. No irreversible action was taken without human authorization.

Evidence and audit trail

Each event, decision, and action was recorded before execution: the authenticated request, key identifier and age, source autonomous system, submitted code, process tree, DNS query, policy decision, operator approval, and patch digest. Records were exported as JSONL for SIEM ingestion and as a human-readable timeline for incident review.

Remediation

The administrator key was removed from the repository and rotated, together with all provider credentials accessible to the gateway. The endpoint was blocked at the API gateway while the fleet was upgraded to 1.83.11. The gateway now runs as a non-root user with a read-only filesystem, and egress is restricted to the model providers in use. Secret scanning was enabled across repositories.

The key had been publicly exposed for seven months. Detection was possible because the credential's first use from a new network, the first invocation of the endpoint, and the shell spawn were all outside the established baseline.

Conclusion

Detection did not depend on prior knowledge of CVE-2026-40217. It depended on three deviations from normal behavior: a long-lived credential used from a new network, an endpoint invoked for the first time, and a shell process spawned by a service that should never spawn one. The patch removes this sandbox weakness. Behavioral baselining provides coverage for the next gateway vulnerability.

This case study is a composite scenario based on the public advisory GHSA-wxxx-gvqv-xp7p for CVE-2026-40217. Client details have been anonymized and the timestamps are illustrative.

See what our system sees.

Bring us your infrastructure. We will show you what our system sees.

[email protected] Book a briefing