Insecure Deserialization in AI Model Format Loading
Loading a model file can run attacker code, and safer weight formats alone won't stop it.

Loading an AI model file can run attacker code as well as read weights. Insecure deserialization makes that possible when a loader treats file contents as instructions. Preventing it requires more than changing formats or scanning downloads. Teams need to control weight files, configuration loaders, and the channels that move serialized objects between processes.
Why loading an AI model file can execute attacker code
Pickle hands a file’s contents to a stack-based virtual machine that executes opcodes. Those instructions can invoke Python functions during deserialization, before the loading application can inspect the result. PyTorch’s torch.load() calls Python’s pickle module internally for pickle-based model files. The file is therefore more than stored data. It can direct what the loading process does.
The exploit primitive is the __reduce__ method. An attacker can embed a class whose __reduce__ returns (os.system, ("malicious command",)), causing pickle to execute the command when the object is reconstructed. The Pickle VM’s instructions, including GLOBAL, permit operations on numerical weights and references to arbitrary Python callables. Loading becomes the execution trigger.
PickleBall, published at CCS’25, establishes that this behavior is part of pickle’s design. The Pickle Machine reconstructs objects by executing instructions that can invoke Python classes and functions. Inspecting the resulting model after unrestricted deserialization is too late to prevent code that ran while creating it.
How far the pickle attack surface extends across the ML stack
The exposure extends beyond a single PyTorch call. PickleBall identifies executable metadata or callbacks across torch.save and torch.load, pickle, joblib, dill, numpy, H5/HDF5, and torch.jit.save. These formats share the danger of reconstruction doing more than reading inert values. TensorFlow developers also describe SavedModel as insecure when loading untrusted models. Replacing one API does not settle the broader question.
Aviatrix Threat Research described January 2026 disclosures involving NVIDIA NeMo, Salesforce uni2TS, and Apple ml-flextok in which insecure use of Hydra’s instantiate() let model metadata select arbitrary callables through _target_. The weights were not the execution mechanism. Even with a safe weight file, a configuration loader can turn metadata from outside into function calls.
Distributed inference adds a third route through serialized Python objects sent between processes over ZeroMQ or gRPC. Channels that trust the internal network may pass the data they receive straight to pickle.loads() without checking it. Across these three routes, the ecosystem has built a culture of sharing models on top of mechanisms that were never designed to make untrusted input safe.
The CVE pattern: how the same flaw has produced critical vulnerabilities across inference frameworks
CVE-2025-32444 shows how a cluster communication shortcut becomes remote code execution. In vLLM’s Mooncake integration, recv_pyobj() in mooncake_pipe.py implicitly called pickle.loads() on data arriving through ZeroMQ sockets bound to all network interfaces. The flaw affected versions 0.6.5 through 0.8.4 and was fixed in 0.8.5. Its CVSS v3.1 score was 10.0.
SGLang illustrates why narrowing network access is not the same as removing unsafe deserialization. CVE-2026-3059 and CVE-2026-3060 were assigned in February 2026 and published by CERT/CC in March. A May 2025 change had restricted the ZeroMQ bind address without removing pickle deserialization. As of March 18, 2026, pickle.loads() remained in encode_receiver.py, with no fix shipped. The underlying execution mechanism was unchanged.
Aviatrix’s research described CVE-2025-23304 in NeMo versions below 2.3.2, where malicious .nemo metadata reached Hydra’s instantiate(), and a vulnerability in uni2TS versions 1.2.0 and below. load() further demonstrates that weights_only` is not a universally safe default.
Hugging Face LeRobot’s CVE-2026-25874 exposed the communication variant through an unauthenticated gRPC channel in its asynchronous inference pipeline. Payloads went directly into pickle.loads(), where a crafted __reduce__ ran attacker commands on the GPU host. This was a project from the organization that created safetensors. The recurring failure was not a lack of safer weight formats, but trust in inputs and channels that could reach an executable loader.
How attackers weaponize public model repositories as the delivery channel
Public model repositories give attackers a delivery route to teams that never operate distributed inference clusters. JFrog documented approximately 100 malicious AI and ML model files on Hugging Face in March 2024, including pickle files with reverse shell payloads that ran silently on load. One model from the account “baller423” connected to an external IP and gave attackers interactive shell access to a data scientist’s workstation. The download looked like a model artifact. Its loader made it an entry point.
Rapid7 Labs found another route in which attackers used pickle-based .pth files shared through Hugging Face to install remote access trojans. PickleBall documents payloads for system fingerprinting, credential theft, and reverse shells. Attacks need not stop at the host system, either. Trail of Bits’s “Sleepy Pickle” technique targets the model by hooking its inference function to record private user data, extending harmful behavior into inference.
Platforms can distribute content without mandatory signing, comprehensive behavioral analysis, or enforced format restrictions, leaving practitioners to infer safety from where a file is hosted. That trust is easy to borrow. Downloading a pickle-based model for loading is functionally a decision to run untrusted code, even when the file arrives through a familiar hub.
Why safetensors alone does not close the attack surface
Safetensors removes executable deserialization from the weight-loading path through a simple header-plus-raw-buffer format. Its loading process has no code path for invoking arbitrary Python callables from the file. Trail of Bits audited the format in 2023 under a joint commission from Hugging Face, EleutherAI, and Stability AI. This is a substantial security improvement. It addresses the dangerous mechanism rather than trying to recognize every malicious use of it.
That protection stops at the format boundary. The NeMo, uni2TS, and FlexTok configuration flaws demonstrate why safe weights do not make attacker-controlled Hydra targets safe. LeRobot’s gRPC flaw likewise shows how serialized objects can reach pickle through runtime communication, regardless of how weights are stored. These are separate execution paths. Format migration does not remove them.
Migration is also incomplete in practice. PickleBall found that 44.9% of popular Hugging Face models still used pickle, while an empirical study found that most repositories converted by Hugging Face’s automated conversion bot retained their original pickle files. Research published for the 2026 IEEE Symposium on Security and Privacy also uncovered six zero-day vulnerabilities across Keras and Skops despite their reliance on data-based persistence. Safetensors is a necessary step for weight safety, but stopping there addresses only one of the three vectors.
Why scanner-based defenses are weaker than they appear
Cloud Security Alliance’s May 2026 analysis describes three PickleScan bypass vulnerabilities discovered in December 2025, namely CVE-2025-10155, CVE-2025-10156, and CVE-2025-10157 [4][1][2]. Each received a CVSS v4.0 score of 9.3. Organizations relying solely on that scanner had months of potentially undetected exposure. The scanner itself was part of the security boundary.
PickleBall shows that scanners commonly reject known dangerous callables while missing attacks that use previously unexplored callables or framework features. MOAT, a 2026 study from Politecnico di Milano, describes how static, signature-driven rules struggle across formats and frameworks and produce both false negatives and false positives. A clean result means only that the scanner found no recognized problem.
ShadowPickle makes that distinction concrete by using the Pickle VM’s own deserialization mechanism to evade existing model hub scanners. Its attacks proved more evasive than prior state-of-the-art pickle attacks. Hub-level experiments also showed that exploits for Keras and Skops zero-days could pass Hugging Face’s integrated scanning tools. Scanning remains useful as one signal, but it cannot serve as permission to trust every file it accepts.
What a layered defense for model loading actually requires
Mandate safetensors for new model artifacts and audit converted repositories for residual pickle files. Apply the same safety requirement to configuration loading by validating and restricting Hydra instantiate() paths so external metadata cannot choose arbitrary _target_ callables. The controls must cover both inputs. Otherwise, removing executable weights merely leaves executable metadata as the next route.
Legacy pickle inventories need an enforced loading policy while migration proceeds. PickleBall statically analyzes an ML library’s source to derive a custom allowlist of callables that benign models legitimately invoke, then enforces it during loading through a drop-in pickle replacement. Its evaluation correctly loaded 79.8% of benign pickle-based models while rejecting all malicious examples in its dataset. Those results have a defined scope. They support a concrete option for legacy artifacts within the evaluation’s scope.
Runtime controls should limit what a model can do even when earlier checks fail. Load models in an isolated process or container with restricted filesystem and network access before promotion to production. Blocking outbound connections prevents a load-time reverse shell from phoning home. MOAT adds lifecycle-aware behavioral analysis across loading, inference, and training, using deviations from expected system calls as a signal. Its RE-MOAT implementation detected all evaluated attack classes with a close-to-zero false-positive rate against real-world Hugging Face artifacts and CVE proof-of-concept exploits.
For communication channels, bind ZeroMQ and gRPC listeners to loopback interfaces where communication is local, and enforce mutual TLS for inter-node communication. Treat any channel that accepts serialized Python objects from non-loopback addresses as a remote code execution vector until it is proven otherwise. Network restrictions are not a deserialization fix. Their role is to constrain access while the execution risk receives separate scrutiny.
Verify provenance and cryptographic integrity, prefer publishers with verified organizational identities, and pin model versions as carefully as software dependencies. A previously safe model may be replaced with a malicious variant. Extend that scrutiny to agent skill registries, too. The same Cloud Security Alliance analysis documents the ClawHavoc campaign as evidence that this delivery pattern now extends beyond weight files.
How to test model-loading pipelines for deserialization vulnerabilities before an attacker does
A security assessment should test the serialization format, configuration loader, and inter-process channels on their own. For Hydra, test external model metadata for influence on _target_. For ZeroMQ and gRPC, inspect socket bindings and follow received data to any unvalidated pickle.loads() call. These decisions are often made inside serving code.
Inspect YAML loaders for unpinned PyYAML versions and acceptance of arbitrary tags, using Docling’s CVE-2026-24009 as a documented example of exposure introduced through a transitive dependency. Check converted repositories for original pickle files that remain available beside safetensors artifacts. The OWASP AI Testing Guide version 1, announced November 26, 2025, places this loading surface within its infrastructure test category. That scope reaches beyond testing model responses.
A torch.load() call without weights_only=True is a flag, while a working pickle payload that executes a shell command on load demonstrates a vulnerability. The assessment needs evidence of the reachable execution path. Treating every flag as proof obscures which controls actually failed.
Complete coverage requires whitebox access to inference serving code, configuration loaders, and inter-process plumbing. Code-aware scanning on pull requests should keep checking for regressions and fixes that are incomplete. SGLang’s bind-address change shows why a review must catch changes to access restrictions that leave pickle.loads() in place. The standard is ongoing scrutiny of the code that turns model inputs into execution.
Sources
- 2025-2026 Remote Code Execution in AI/ML Python Libraries — Supply Chain Vulnerability
- PickleBall: Secure Deserialization of Pickle-based Machine Learning Models
- Poisoned Pipelines: Malicious AI Model and Skill Repositories
- ShadowPickle: Evading Machine Learning Model Scanners via Stealthy Pickle Deserialization Attacks
- Lifecycle-Aware Dynamic Analysis for Secure ML Model Execution
- On the (In)Security of Loading Machine Learning Models


