Skip to main content

pickle-sentry

The pickle scanner for your code and your supply chain — not just your model files.

CI PyPI Python License: MIT

Scan code and dataset files for unsafe pickle deserialization — including the Hugging Face datasets pandas builder RCE, CVE-2026-57845 (CVSS 8.8).

Pickle is code, not data. Any file, checkpoint, or dataset that passes through a pickle loader executes whatever its author put in it. pickle-sentry finds those paths in your code, and inspects pickle files by disassembly only — it never executes the files it inspects (its test suite proves this with a canary payload).

pickle-sentry demo

Full walkthrough: docs/DEMO.md.

Quick start

pip install pickle-sentry

pickle-sentry .                                   # scan a project (code + pickle files)
pickle-sentry hub user/repo --repo-type model     # scan a Hugging Face repo before loading it
pickle-sentry . --fail-on high                    # as a CI gate: exit 1 on high+

Zero dependencies. Python 3.9+.

How it differs

Most pickle scanners inspect model files. pickle-sentry also inspects the code that loads pickles and the packages you are about to install — the two places the CVE-2026-57845 class of bug actually lives.

Capability pickle-sentry Model-file scanners (Picklescan / ModelScan / Fickling)
Inspect pickle / PyTorch files without executing them ✓ ✓
Scan source code for unsafe loaders (pickle.load, torch.load, read_pickle, …) ✓ —
Flag load_dataset("pandas", ...) as CVE-2026-57845 ✓ —
Scan a Hugging Face Hub repo remotely ✓ partial (Picklescan)
Scan a PyPI package before installing it ✓ (pipeline pattern) —
Deep pickle decompilation / allowlist VM analysis — ✓ (Fickling)
Many non-pickle model formats (Keras, TF, ONNX, …) — ✓ (ModelScan / ModelAudit)
Zero dependencies, one-line CI gate, SARIF output ✓ varies

Use pickle-sentry alongside a model-file scanner, not instead of one: it covers the loader and supply-chain surface they do not.

Why now

CVE-2026-57845 (published 23 Oct 2026): Hugging Face datasets through 5.1.0 — the latest release — routes load_dataset("pandas", data_files=...) to pandas.read_pickle(). A crafted pickle runs arbitrary Python with the victim's privileges the moment the dataset loads. The upstream fix (huggingface/datasets#8879) disables the pandas builder, but no patched release exists yet. Until one ships, the mitigation is: find every place you load pickle-backed data, and migrate to Parquet / CSV / JSON / Arrow.

Use

pickle-sentry scan-path/                     # text report, exit 1 on high+
pickle-sentry . --format json --output report.json
pickle-sentry . --format sarif --output report.sarif   # for GitHub code scanning
pickle-sentry . --fail-on critical           # CI: only fail on critical
pickle-sentry . --exclude /tests/            # production surface only

Scan a Hugging Face Hub repo (new in 0.2.0)

pickle-sentry hub stanfordnlp/imdb                          # a dataset
pickle-sentry hub hf-internal-testing/tiny-random-bert --repo-type model
pickle-sentry hub user/repo --max-size-mb 16 --format json

Lists the repo's files via the Hub API, downloads pickle-family files (.pkl, .pickle, .joblib, .pt, .pth, and classic pytorch_model.bin) and inspects them by disassembly — including the pickle stream inside torch zip archives — and AST-scans any Python files in the repo. Files over the size cap are flagged, not downloaded. Set HF_TOKEN for private repos. Nothing downloaded is ever executed.

What it catches

In Python code (AST scan — parses, never imports your code):

Rule Severity What
HF-DATASETS-PANDAS-BUILDER critical load_dataset("pandas", ...) — CVE-2026-57845
UNSAFE-DESERIALIZATION high pickle.load/loads, dill, cloudpickle, marshal, shelve, joblib.load
PANDAS-READ-PICKLE high pandas.read_pickle(...)
TORCH-LOAD-WEIGHTS-ONLY-FALSE high torch.load(..., weights_only=False)
TORCH-LOAD-NO-WEIGHTS-ONLY medium torch.load(...) with no explicit weights_only=True
YAML-UNSAFE-LOAD medium yaml.load(...) without a SafeLoader
NUMPY-ALLOW-PICKLE high numpy.load(..., allow_pickle=True)

In data files (disassembly via pickletools, never unpickled):

Rule Severity What
PICKLE-DANGEROUS-REDUCE critical Pickle calls os.system, subprocess.*, eval, exec, etc. via REDUCE
PICKLE-REDUCE-CALLABLE high Pickle invokes a non-standard callable via REDUCE (the CVE PoC payload's shape)
PICKLE-DANGEROUS-GLOBAL / PICKLE-SUSPICIOUS-MODULE high/medium Dangerous globals referenced without a reduce
PICKLE-FILE-PRESENT medium Any other .pkl / .pickle / .joblib file, and pickle streams inside torch .pt/.pth zip archives

Real-life use case

docs/USE-CASE.md walks through a real one end to end: scanning the actual published CVE-2026-57845 PoC repository before touching it. pickle-sentry flags the vulnerable loader (run_poc.py:139, critical) and disassembles the live payload (attacker-controlled.pkl, high) — and the PoC's own marker.txt proves the payload never executed during the scan.

Live examples

Scanned two real codebases on 9 Nov 2026 — full results, methodology, and honest limits in docs/LIVE-EXAMPLES.md:

  • huggingface/datasets: 258 files, 24 findings — and exactly one in production source: the CVE sink itself, pd.read_pickle(f) at packaged_modules/pandas/pandas.py:56.
  • scikit-learn: 1,037 files, 73 findings — 16 outside tests, concentrated in sklearn/datasets/ loaders unpickling cached copies of remotely fetched datasets.

Also included: a composite GitHub Action (action.yml, use it as uses: Sun-Wukhan/pickle-sentry@main) and a pre-commit hook (.pre-commit-hooks.yaml). Use --exclude /tests/ to cut test-fixture noise.

CI/CD

Call pickle-sentry as a pipeline gate in GitHub Actions, GitLab CI, Azure Pipelines, Jenkins, or any runner with Python 3.9+:

- uses: Sun-Wukhan/pickle-sentry@main
  with:
    path: .
    fail-on: high

Or call the PyPI package directly:

python -m pip install "pickle-sentry==0.2.1"
pickle-sentry . --fail-on high

Exit 0 means no finding reached the threshold; exit 1 fails the job; exit 2 means the scan itself could not run. Full examples — including SARIF upload to GitHub code scanning and Hub scans in a pipeline — are in docs/CI-CD.md, with copy-ready files under examples/cicd. A worked supply-chain example scans the existing datasets==5.1.0 wheel without installing it and fails on the real CVE sink at pandas.py:56: docs/EXISTING-PACKAGE-EXAMPLE.md.

Demo

pickle-sentry examples/vulnerable   # flags the CVE pattern + every sink, exit 1
pickle-sentry examples/safe         # clean, exit 0
pickle-sentry examples/hf-datasets-pandas.py
# ^ the actual upstream datasets pandas builder (verbatim from
#   huggingface/datasets main): flags pd.read_pickle(f) at line 56 —
#   the exact sink behind CVE-2026-57845.

Migrate off pickle

  • Datasets: load_dataset("parquet" | "csv" | "json" | "arrow", ...)
  • Your own DataFrame: Dataset.from_pandas(df) instead of a pickle file
  • DataFrames on disk: df.to_parquet(...) / pd.read_parquet(...)
  • Torch: torch.load(path, weights_only=True)

Tests

pip install pytest
pytest

The inspector tests build a real malicious pickle (__reduce__ → os.system) and assert two things: it is flagged critical, and the payload's canary file never appears — i.e. inspection did not execute it.

Licence

MIT

Metadata

Release files for pickle-sentry 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pickle-sentry 0.2.1
File Size Uploaded Provenance Actions
pickle_sentry-0.2.1.tar.gz 20.4 kB With provenance Details for pickle_sentry-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pickle-sentry 0.2.1
File Interpreter ABI Platform Actions
pickle_sentry-0.2.1-py3-none-any.whl Python 3 none any Details for pickle_sentry-0.2.1-py3-none-any.whl

Total release size: 36.9 kB

Release files / pickle_sentry-0.2.1.tar.gz

Download URL pickle_sentry-0.2.1.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0e570a1a2cb90daf77d9f61cbc1c6f32478544fad0fc1ba6c533dd6f3205c2ba
BLAKE2b-256 checksum
How to use checksums
f149832facd8589e90da60d81bab4ddc15f75e93763999006d43ae204d93a85b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / pickle_sentry-0.2.1-py3-none-any.whl

Download URL pickle_sentry-0.2.1-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89a431e4046d8ffd7c0710e905016bbcc4574f0cb897e53816c3e2be60f07b5b
BLAKE2b-256 checksum
How to use checksums
4cadd3a38f8a6e9d381b8b54fea84f8a9deb117a18e25e6c33ccb180d0ce5911
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for pickle-sentry 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pickle_sentry-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page