CPython Memory Flaw Raises Risks for AI Model Inference Servers
A crafted AI model template can turn a CPython memory-safety bug into code execution inside an inference server. The practical exposure is clearest for hosting services that let customers upload their own models: a compromised serving process may handle requests across multiple customers and run on shared cloud infrastructure.
RunSybil researchers demonstrated the issue with a modified Qwen2.5-0.5B-Instruct model. Its backdoored chat_template.jinja file bypassed Jinja’s sandbox when loaded by an inference engine such as vLLM, allowing arbitrary code to run in the serving process.
There’s a dispute over what the bug means for CPython’s security. The Python Security Response Team (PSRT) acknowledged the underlying interpreter defect and the contribution that fixed it, but said sandbox escapes aren’t within CPython’s security threat model. RunSybil sees a more immediate supply chain risk for AI inference infrastructure.
A stale type-parameter list opens the way
The exploit hinges on how CPython handles generic types. RunSybil says the interpreter can keep using a cached list of parameters after a callback modifies an object. When CPython later looks for a newly added parameter in that stale list, it can get an invalid index. A check that would catch the condition is disabled in normal release builds, leaving the interpreter able to access memory outside the expected bounds.
A bad address will often crash Python. But, as RunSybil researcher Darius Houle explained, an address that happens to point to a live Python object can give the callback a reference to an object the sandbox meant to hide. The researchers used recovered references to reach the classes and functions needed to build executable code.
The attack worked even with objects made available to templates in otherwise empty sandbox contexts. That detail matters for systems that assume a template engine’s restrictions can contain an untrusted model.
BYOM services face the clearest exposure
RunSybil shared proof-of-concept exploits with several inference providers offering bring-your-own-model features. In those services, a model and its template may come from outside the provider’s control, while the template runs as part of the model serving workflow.
“By exploiting this vulnerability, attackers could gain a foothold inside servers responsible for processing millions of user requests,” Houle wrote. He also warned that attackers could target the cloud infrastructure hosting those workloads.
My read is that the risk depends heavily on deployment boundaries: a template escape matters most when untrusted models run in a process with access to shared services or sensitive infrastructure. RunSybil’s recommendation is to treat sandboxes, template engines and expression evaluators as best-effort controls, not standalone security boundaries.
The fix is in newer branches; Python 3.12 remains a gap
RunSybil reported the issue to CPython, the Pallets Project, which maintains Jinja, and Hugging Face. The researchers said they encountered differing views about which project should address the problem. PSRT said sandbox escapes belong with the maintainers of the affected sandboxing software because CPython doesn’t promise to contain untrusted Python code.
PSRT also said RunSybil submitted its report by email instead of through CPython’s designated private GitHub vulnerability channel. The researchers, for their part, raised concerns about the reach of the fix across supported Python versions.
RunSybil submitted a patch that was merged into CPython’s main development branch on Aug. 14. PSRT said the change was backported to Python 3.13, 3.14 and 3.15 as a regular bug fix, rather than a security fix. There was no backport to Python 3.12, which RunSybil says remains widely used across AI infrastructure.
Houle warned that this could delay broad adoption of the memory-safety fix: “With major portions of the AI ecosystem still solidly aligned on Python 3.12, we might not see organic adoption of our memory-safety fixes until late 2028, when it reaches its end-of-life date.” For inference providers accepting external models, the immediate takeaway is to review how templates run, what the serving process can access, and which Python branches their deployments use.