CPython Memory Bug Raises Sandbox Risks for AI Model Inference Servers

| 5 min read

A crafted AI model template can turn a CPython memory-safety bug into code execution inside an inference server. The practical risk falls on providers that let customers upload models: a compromised serving process may handle requests across multiple customers and expose the cloud infrastructure behind it.

That’s RunSybil’s assessment of a flaw in CPython’s handling of generic types. The Python Security Response Team (PSRT) accepts the underlying bug and the fix, but rejects the claim that the demonstration constitutes a CPython security vulnerability. The dispute comes down to responsibility: should the interpreter protect applications that use Python sandboxes to run untrusted code?

Stale type data can expose hidden objects

RunSybil researcher Darius Houle said the bug involves CPython reusing a cached list of type parameters after a callback has changed an object. When the interpreter searches that stale list for a newly added parameter, it can get an invalid index. A check that would catch the condition is disabled in standard release builds, allowing an out-of-bounds memory access.

Many invalid addresses would simply crash the interpreter. But if the access lands on a live Python object, the callback can obtain a reference to it—even when the sandbox has not exposed that object. RunSybil used the references to reach Python classes and functions needed to build executable code.

Houle said the exploit relies on objects available to templates even in an otherwise empty sandbox context. That detail matters for deployments that assume a restricted template environment keeps model-provided code away from sensitive Python capabilities.

A model file becomes the delivery path

For its demonstration, RunSybil altered Qwen2.5-0.5B-Instruct by adding a backdoored chat_template.jinja file. When loaded through an inference engine such as vLLM, the template could escape Jinja’s sandbox and run arbitrary code in the serving process.

Jinja templates structure interactions between users and large language models. In bring-your-own-model services, a customer-supplied model can therefore carry the malicious template into infrastructure used to serve requests. RunSybil said it shared proof-of-concept exploits with several inference providers that support model uploads.

The researchers disclosed the issue to CPython, the Pallets Project, which maintains Jinja, and Hugging Face. Houle described the scenario as a supply chain risk for inference providers, library developers, and model users. The exposure depends on how a service handles externally supplied models and what protections sit around its serving process.

The security classification remains contested

PSRT told CSO that it appreciates RunSybil’s contribution but does not consider the sandbox escape a CPython security vulnerability. Its position follows CPython’s stated threat model: the interpreter does not promise to sandbox untrusted Python code, and escapes should be handled by the maintainers of the sandboxing software.

PSRT also disputed RunSybil’s account of the disclosure process. It said the researchers sent their report by email instead of using CPython’s designated private GitHub vulnerability reporting channel.

That disagreement affects how operators should read the patch. RunSybil submitted a fix that CPython merged into its 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 update.

Python 3.12 is the adoption concern

RunSybil says the fix has not been backported to Python 3.12, which it describes as widely used across AI infrastructure. Houle warned that adoption could lag until that branch reaches its end-of-life date in 2028.

For hosting teams, the immediate takeaway is architectural: treat template sandboxes and expression evaluators as limited safeguards, and place independent controls around workloads that process customer-supplied models. A fix in newer Python branches helps, but the version mix across inference stacks will determine how quickly the memory-safety issue is addressed in practice.

Source: Richard Brown · www.csoonline.com