BerriAI LiteLLM Guardrail Sandbox Escape RCE
CVE-2026-40217 is a critical arbitrary-code-execution vulnerability in BerriAI LiteLLM, a widely used open-source LLM proxy/gateway. LiteLLM's guardrail feature includes a "test custom code" facility that runs user-supplied guardrail code in a sandbox. The sandbox can be escaped by rewriting Python bytecode, allowing an attacker to break out and execute arbitrary code in the context of the LiteLLM process (reported running as root in some deployments).
The vector is a request to POST /guardrails/test_custom_code. CVSS is 8.8- the attacker needs minimal low-privilege access, for example a valid API key or low-tier account, so this is not a fully unauthenticated RCE, though that privilege is common in multi-tenant AI gateways. LiteLLM sits at a privileged chokepoint in AI stacks: it brokers model access and stores provider API keys, so code execution there yields those keys and a foothold into the surrounding environment.
Although disclosed on 2026-04-10, the flaw was added to CISA's Known Exploited Vulnerabilities catalog only on 2026-11-18 (remediation due 2026-12-02), after Zenity Labs observed threat actors abusing the guardrail tester to run code as root. A public proof-of-concept and a Nuclei template exist, and EPSS sits around the 99th percentile. LiteLLM also ships bundled inside Red Hat Ansible Automation Platform 2.6, OpenShift AI 3.3 and Lightspeed Core, so organizations may be exposed without having deployed LiteLLM directly.
• Patch on an emergency basis. Upgrade LiteLLM to the fixed release — confirm the exact fixed version against the vendor / Snyk / Red Hat advisory, as sources list different cut-offs. For bundled products, apply the Red Hat errata RHSA-2026:24866 and RHSA-2026:30056 (Ansible Automation Platform 2.6, OpenShift AI 3.3, Lightspeed Core), and inventory any other product that embeds LiteLLM. • Reduce exposure now: restrict or disable the guardrail custom-code test feature and the /guardrails/test_custom_code endpoint, and block it at the proxy/WAF if patching must wait. Do not expose the LiteLLM admin/guardrail API to the internet; place it behind authentication and tighten which API keys hold guardrail access (the flaw needs only low privilege). • Assume compromise for any internet-reachable or multi-tenant LiteLLM instance left unpatched during the exploitation window. Rotate all provider/model API keys and any credentials LiteLLM stored or brokered, plus the LiteLLM master key and database credentials; review the host for unexpected child processes and outbound connections and new accounts; check logs for POST requests to /guardrails/test_custom_code; and watch for abuse of proxied model access (unexpected spend, new model routes).
• FortiGuard Labs is actively monitoring this threat activity and will continue to provide updates, including new intelligence, indicators and protection guidance. • FortiGuard Intrusion Prevention System: The signature LiteLLM.test_custom_code.Command.Injection (IPS 62918) is available to detect exploit attempts targeting CVE-2026-40217 ( • FortiGuard Antivirus & Behavior Detection: Delivers protection against known malware and uses advanced behavioral analysis to detect and block unknown post-exploitation payloads. • Indicators of Compromise (IOCs) Service: The FortiGuard team is continuously monitoring for emerging threats and new IOCs. • FortiGuard Incident Response: Organizations suspecting a compromise can the FortiGuard Incident Response team for rapid investigation and remediation support — API-key theft, model-access abuse, lateral movement. • Note: network controls do not remediate an application-level compromise of the LiteLLM host; prioritize upgrading LiteLLM and restricting the guardrail test endpoint.
Experienced a Breach? We're here to help
FortiGuard Threat Signal
