Languagemodels 1.0.1 Patches High-Severity Jinja2 Injection Flaw

A high-severity remote code execution vulnerability in the Python library languagemodels has been patched in version 1.0.1. The flaw, identified as CVE-2026-139989, allowed attackers to execute arbitrary code by crafting malicious chat templates in Hugging Face model configurations. The vulnerability stems from the use of an unsandboxed Jinja2 environment in the config.use_hf_model function, which processes model metadata before downloading weights. Although the attack requires user interaction to select a specific model, it demands no special privileges and executes with the victim's process rights. The issue carries a CVSS 3.1 score of 7.8 and a CVSS 4.0 score of 8.5, reflecting high impacts on confidentiality, integrity, and availability. The fix replaces the standard Jinja2 environment with a sandboxed immutable version, mirroring security practices in the Hugging Face transformers library.
Key points
- CVE-2026-139989 affects languagemodels version 1.0.0 and earlier, allowing remote code execution via malicious Hugging Face model chat templates.
- The vulnerability exists in the config.use_hf_model function, which uses an unsandboxed Jinja2 environment to render model metadata, specifically the tokenizer_config.json file.
- Exploitation requires user interaction to select a model but no special privileges; the code executes with the victim's process privileges at the time of model selection.
- The flaw is classified as CWE-1336 (Improper Neutralization of Special Elements Used in a Template Engine) and is analogous to previous unsandboxed Jinja2 issues in other AI libraries.
- Version 1.0.1 was released on PyPI to patch the issue by replacing the standard Jinja2 environment with jinja2.sandbox.ImmutableSandboxedEnvironment.
Background
This incident follows a recent trend of high-severity vulnerabilities in AI and machine learning libraries. In late November 2026, similar flaws were reported in DeepSpeed, AutoGPT, and browser-use, involving insecure deserialization, memory exhaustion, and allowlist bypasses. The languagemodels library, designed for local LLM inference with low RAM requirements, is particularly susceptible to this type of attack because it renders chat templates before downloading model weights, exposing users to risks from third-party published models.
Why it matters
The vulnerability highlights the security risks associated with dynamically rendering external configurations in AI libraries. Because the flaw executes code with the victim's privileges, any user attempting to load a third-party Hugging Face model could be compromised. The high CVSS scores and the ease of exploitation via a simple model selection underscore the need for strict sandboxing in template engines used in AI development tools.
What to watch
Users of the languagemodels library should immediately upgrade to version 1.0.1 or later to mitigate the risk of remote code execution. Developers should review their use of Jinja2 environments to ensure that any processing of external or user-influenced input is handled within a sandboxed context to prevent similar template injection attacks.
Want the full story? Read the original reporting
Read on CVEs | Zero Wire | Cloudflare Radar