Pickle is code, not data: scanning your Python and ML models for unsafe deserialization
A Python pickle is a file format for storing and rebuilding Python objects. The article’s key warning is that a pickle is also a program for a small stack-based virtual machine. Its contents are instructions, or opcodes, that tell Python how to reconstruct an object. During loading, Python interprets those instructions. In particular, a pickle can use REDUCE to call a function specified by the file. The article gives os.system as an example and explains that an object’s reduce can direct this call. A crafted file can therefore run arbitrary Python when it is unpickled. This behavior is documented, not a bug in pickle. The danger is loading files you did not create or trust, such as shared checkpoints, datasets, or joblib files. A familiar-looking call like pickle.load() can execute the file’s instructions with the program’s privileges, so the article recommends migration to formats such as Parquet, CSV, JSON, or Arrow where possible.
What is a Python pickle, and why can loading one run code?
A Python pickle is a file format for storing and rebuilding Python objects. The article’s key warning is that a pickle is also a program for a small stack-based virtual machine. Its contents are instructions, or opcodes, that tell Python how to reconstruct an object.
During loading, Python interprets those instructions. In particular, a pickle can use `REDUCE` to call a function specified by the file. The article gives `os.system` as an example and explains that an object’s `__reduce__` can direct this call. A crafted file can therefore run arbitrary Python when it is unpickled.
This behavior is documented, not a bug in pickle. The danger is loading files you did not create or trust, such as shared checkpoints, datasets, or joblib files. A familiar-looking call like `pickle.load()` can execute the file’s instructions with the program’s privileges, so the article recommends migration to formats such as Parquet, CSV, JSON, or Arrow where possible.
What does CVE-2026-57845 affect, and how can a crafted dataset trigger it?
CVE-2026-57845 concerns Hugging Face datasets through version 5.1.0, identified in the article as the latest release. It was published on 23 October 2026 with a CVSS score of 8.8. The issue matters because a normal-looking dataset-loading operation can reach an unsafe pickle loader.
The vulnerable route is `load_dataset("pandas", data_files=...)`. It leads to `pandas.read_pickle()`, which loads a pickle supplied as dataset data. An attacker can craft that pickle so its instructions execute arbitrary Python as soon as the victim loads the dataset. The code runs with the victim’s privileges, rather than being limited to reading data.
The article reports that the upstream fix, huggingface/datasets#8879, disables the pandas builder. However, it also says no patched release exists yet. Until then, the risk is relevant to users loading untrusted data through this route. The article presents pickle-sentry as a way to flag this specific loader pattern as critical before the dataset is loaded.
How broad is the risk across Python and machine-learning workflows—which loaders and file types can be involved?
The article describes the risk as spread across shared checkpoints, datasets, joblib files, and ordinary loader calls in code. Pickle-sentry’s AST scan checks calls to `pickle`, `dill`, `cloudpickle`, `marshal`, `shelve`, and `joblib`, as well as `pandas.read_pickle`. It also flags unsafe `torch.load`, YAML loading without a SafeLoader, and NumPy loading with `allow_pickle=True`.
The scan covers more than direct pickle files. It checks `.npy` object arrays, `.npz` members, and `.keras` Lambda layers containing marshalled bytecode. It also checks headers in safetensors and GGUF files. Compressed wrappers such as gzip, bzip2, xz, and zlib, plus zip and tar members, are peeled and scanned. A 7-Zip archive is marked opaque because the standard library cannot inspect it.
The tool also flags `load_dataset("pandas", ...)` as critical for CVE-2026-57845. It can scan a project, installed packages, or a remote Hugging Face Hub repository. The breadth matters because scanning model files alone can miss code that unpickles cached remote datasets.
What can an attacker do if a program loads a malicious pickle?
If a program loads a malicious pickle, the file can cause code to run during deserialization. The article says a crafted pickle can execute arbitrary Python with the victim’s privileges. That means the possible actions are limited by the permissions available to the program, but the article does not list particular actions beyond code execution.
One example is a pickle whose `__reduce__` directs a call to `os.system`. The file’s instructions are interpreted when Python unpickles it. The article stresses that this is documented pickle behavior, which is why an ordinary call such as `pickle.load()` can be dangerous when its input comes from an untrusted source.
Pickle-sentry is designed not to trigger that consequence while inspecting files. Its test suite creates a real malicious pickle and checks that it is flagged as critical while a canary file does not appear on disk. The scanner parses code rather than importing it, and it analyzes pickle instructions without executing the files it inspects.
How does pickle-sentry tell the difference between a file that mentions a dangerous function and one that actually invokes it?
Pickle-sentry distinguishes between a pickle that merely refers to a dangerous function and one that actually invokes it. That distinction matters because a global such as `os.system` can appear in a file without being called. The tool reports a referenced but uninvoked dangerous global separately from an active payload.
To make the distinction, the scanner disassembles the pickle with `pickletools` and runs an abstract interpreter over the instructions. It tracks a symbolic stack through operations including `REDUCE` and `NEWOBJ`, along with the pickle memo. It also checks nested pickle streams embedded in byte constants. This lets it follow how values are assembled and used without running the pickle.
A stream that actually invokes `os.system`, `subprocess.*`, `eval`, `exec`, or similar functions receives a critical `PICKLE-DANGEROUS-REDUCE` finding. A dangerous global that is only referenced receives a high- or medium-severity `PICKLE-DANGEROUS-GLOBAL` finding. The scanner never executes the inspected files.
What safer formats or loading options can reduce the risk of unsafe deserialization?
The article presents migration as the longer-term way to reduce unsafe deserialization. For datasets, it names Parquet, CSV, JSON, and Arrow as alternatives to pickle-based storage. These formats avoid relying on the pickle loader for the described dataset use, though the article does not claim any format is safe in every possible context.
For PyTorch, the recommended option is to use `weights_only=True` with `torch.load`. Pickle-sentry flags `torch.load` when `weights_only=False` or when no explicit `weights_only` value is given. For model weights, the article also recommends safetensors where possible; the tool includes header checks for safetensors files.
Migration may take time, so the article describes a scanner that fails CI on a newly detected unsafe loader as a reasonable seatbelt in the meantime. Pickle-sentry can be run on a project, used as a GitHub Action, or installed as a pre-commit hook. Its `--fail-on high` option can make CI exit with status 1 for high-severity findings or worse.
Why can some serialization formats reconstruct executable behavior, while formats such as CSV and JSON are generally treated as data?
The article explains that pickle is a program for a small stack-based virtual machine. Its opcodes describe how to rebuild objects, and a `REDUCE` instruction can call a function. Loading a pickle therefore means interpreting instructions, not merely reading a passive collection of values. A malicious file can use that mechanism to run code.
CSV and JSON are proposed in the article as alternative dataset formats, but it does not explain their parsing model. As general background beyond the article, ordinary CSV and JSON parsers treat file contents as values to parse, not as instructions to reconstruct arbitrary Python objects or call functions. A program can still choose to do something unsafe with parsed values, but that is different from pickle’s built-in object reconstruction behavior.
The distinction is about what the loader is designed to interpret. Pickle can carry behavior as part of object reconstruction; plain CSV and JSON data do not normally carry executable Python behavior. The article’s migration list also includes Parquet and Arrow, and recommends `weights_only=True` for PyTorch and safetensors where possible.
This brief was written by AI from the original reporting and checked by other models. Names, figures and quotes come from the source; read it for full context.
Read more in the JupiteX app
Pulse is free. New stories every 4 hours, each one broken into the questions that explain it.
Or read more news on the web