Nobody Owns This Bug: A CPython Sandbox Escape Shows How AI Model Hosting Falls Between Projects

Nobody Owns This Bug: A CPython Sandbox Escape Shows How AI Model Hosting Falls Between Projects
A memory bug in CPython lets a booby-trapped Jinja chat template break out of its sandbox inside AI inference servers, and the real lesson is that every project in the chain, from Python to Jinja to the serving engine, can reasonably say it isn't theirs to fix.
The bug, briefly
Security researchers reported this month that a memory-safety flaw in CPython, an out-of-bounds read in the interpreter's handling of generic alias type substitution, can be used to escape Jinja's sandboxed template environment and run arbitrary code in the host process. The researchers say they found it in under a day, working with a large language model.
That matters for AI because modern open-weight models ship a chat_template.jinja file that turns a conversation into the token format the model expects. Inference servers render that template inside Jinja's ImmutableSandboxedEnvironment precisely because templates come from whoever published the model. The researchers demonstrated that a model repository with a backdoored template could trigger code execution when served by vLLM, using a small public model as the carrier.
The exposed party is anyone who lets customers bring their own model: the "upload your fine-tune and we'll serve it" offering that many AI hosting platforms now sell. A single malicious model becomes code running on shared inference infrastructure.
No CVE has been mentioned in public reporting. The underlying fix was merged into CPython's main branch on 14 August and, according to the Python Security Response Team (PSRT), backported to the 3.13, 3.14 and 3.15 branches as a regular bug fix, not a security fix. It was not backported to 3.12, which many AI deployments still run and which stays supported until 2028.
Everyone is technically right
What makes this case worth examining is the reaction from each project in the chain:
- CPython (PSRT) acknowledged the bug and thanked the researchers, but said it does "not consider the demonstrated sandbox escape to be a CPython security vulnerability". Running untrusted Python inside a sandbox has never been inside CPython's threat model, and sandbox escapes belong with the sandbox developers.
- Jinja's maintainers said the root cause was in CPython, not Jinja, and pointed the researchers back there.
- vLLM acknowledged the report but, according to the researchers, had not settled on a mitigation.
- Hugging Face, where most models are distributed, did not respond within the 90-day disclosure window, the researchers say.
Each position is defensible on its own terms. CPython has said for years that the language is not a security boundary for hostile code. Jinja's sandbox has always been a best-effort control resting on an interpreter it does not control. Inference engines assumed the template layer was the sandbox's problem. Model hubs host files; they do not run them on your servers.
Put together, though, the result is a real attack path with no single owner, and a fix that arrives in some Python versions as an ordinary bug fix, without the CVE that would make scanners, distributions and compliance teams notice it.
The ones who closed the gap
Two providers show what owning the problem looks like. The researchers say AWS worked with them and put a mitigation in place for Bedrock, and DigitalOcean remediated the issue, adding that its multi-tier isolation contained the attack and no lateral movement was found.
That second detail is the important one. DigitalOcean was not saved by Jinja's sandbox or by a Python patch. It was saved because it never treated the template renderer as the last line of defence. The process that rendered the hostile template simply did not have much to reach.
Why this pattern will keep repeating
AI serving stacks are built from layers that each assume someone else handles hostile input. A model "file" is no longer just weights: it can carry templates, configuration, tokenizer code and, in some formats, executable logic. We have already seen pickle-based model files abused, remote-code flags in loaders and RCE flaws in serving frameworks themselves. Template sandboxes are simply the next layer to give way.
The researchers' recommendation applies more widely than this one bug: treat sandboxed code, template engines and expression evaluators as best-effort controls, and assume an attacker who controls the input can eventually reach arbitrary code execution. With AI-assisted bug hunting now finding interpreter flaws in hours, "eventually" is getting shorter.
Practical takeaways
- Treat every third-party model as untrusted code. That includes its chat template, tokenizer config and any custom code, not just the weights.
- Isolate inference per tenant. For bring-your-own-model services, render templates and run inference in containers or microVMs with no cloud credentials, no metadata service access and tight network egress rules.
- Upgrade Python deliberately. Prefer a CPython branch that received the fix (3.13 or later builds released after the backport) for any workload that relies on sandboxed templates. Check what you run:
python3 --version
python3 -c "import jinja2; print(jinja2.__version__)"
pip show vllm 2>/dev/null | grep -i '^version'
- Review templates before serving. Pin model revisions by commit hash, diff
chat_template.jinjaon every update, and alert on templates that touch attributes, introspection or unusual type operations. - Don't wait for a CVE. This fix shipped as an ordinary bug fix. Track upstream changelogs for the components you rely on as security boundaries, not just vulnerability feeds.
- Ask your AI hosting provider directly how bring-your-own-model workloads are isolated, and whether they have assessed this template escape.
