CVE-2026-40217 is a sandbox escape in LiteLLM's custom-code guardrail. The /guardrails/test_custom_code endpoint (and the equivalent config/DB custom_code guardrail path) accept arbitrary Python source, check it only with a regex blacklist, then execute it with exec(compile(...)) while merely setting exec_globals["__builtins__"] = {}. Because the check inspects the source text rather than the compiled object, an attacker reconstructs blocked dunder names by string concatenation, obtains the real __import__ via http_get.__globals__["__builtins__"], and runs arbitrary OS commands.
The fix commit is 0a1b4427a6c4ee07add32295e331bd0cf9cac572 ("fix(guardrails): replace custom_code sandbox with RestrictedPython"), whose parent 72a461ba4ab5be96902380870b4994adbbcf7ad6 is the vulnerable revision. It deletes code_validator.py (the regex filter validate_custom_code), deletes the __builtins__ = {} / raw exec(compile(...)) blocks in both guardrail_endpoints.test_custom_code_guardrail and CustomCodeGuardrail._do_compile, and replaces them with RestrictedPython (compile_restricted + guarded globals). The functions that existed in the vulnerable version and were modified/deleted are therefore the runtime indicators: the endpoint handler test_custom_code_guardrail, the bypassed validator validate_custom_code, and the compile/exec sinks CustomCodeGuardrail._do_compile, _compile_custom_code, and update_custom_code. build_sandbox_globals/compile_sandboxed are new mitigations introduced by the patch and are NOT vulnerable functions. For Python profilers these are reported as Class.method for methods and bare names for module-level functions (module paths stripped).