AI and store security Research-backed Python

model-file-guardScan pickle, PyTorch, joblib and other ML model files for hidden code before you load them

model-file-guard checks machine learning model files (pickle, joblib, PyTorch, Keras, GGUF, ONNX, safetensors, NumPy) for code that would run when you load them. It reads files the way the loaders do without importing anything, allows only what real models need, and can scan a Hugging Face repo before you download it.

PyPI pip install model-file-guard

Free · MIT license · runs on your machine · no signup PyPI ↗GitHub ↗

Why this matters now

Loading a pickle runs whatever code its author put in it. Blocklist scanners keep being bypassed: picklescan alone has had seven published advisories since 2025.

How model-file-guard works

Every time someone shares a trained model, they share a file. If that file is a pickle (the default for scikit-learn, joblib and older PyTorch code), loading it can run any command its author wanted. A product-recommendation model downloaded from a hub, or a “fixed” model a freelancer sends back, can open a shell on your server the moment your app loads it.

model-file-guard reads the file the way Python would, without running anything, and tells you exactly what it would do: would run: os.system('curl ... | sh'). Files that only rebuild tensors and plain data pass. Files that need your own code are marked for review, so you can allow just those classes.

It also checks the formats that are supposed to be safe. A safetensors file with extra bytes after its tensors, a GGUF file with impossible sizes, a chat template that reaches into Python internals, an ONNX model that reads ../../etc/passwd: these are all real attack shapes, and each has its own check.

Try it

You need Python 3.9 or newer. No other packages are needed.

pip install model-file-guard
model-file-guard path/to/models

Scan a Hugging Face repo before you download it:

model-file-guard hf OWNER/REPO

And check whether your installed PyTorch, Keras, ONNX or llama-cpp-python has a known model-loading flaw:

model-file-guard env

Why I built it

My research is on efficient and secure machine learning inference, much of it with gradient-boosted tree models saved as joblib files. The popular scanner could not read an ordinary scikit-learn joblib file with arrays in it, and blocklist scanners keep being bypassed by imports nobody listed. I wanted a scanner that reads files exactly as the loaders do, allows only what real models need, and stays free.

Free and open source under the MIT license. Not affiliated with PyTorch, Hugging Face or any scanner vendor. Need help securing your AI supply chain? Book a call.

Agent skill included

Let your AI coding agent run model-file-guard for you

The model-file-guard skill works with Claude Code, Codex, Cursor, Gemini CLI and other agents that read SKILL.md files. It runs the tool, explains each finding in plain words and helps you fix it.

npx skills add MuhammadAhmadZia/model-file-guard --skill model-file-guard

Using the Claude or ChatGPT apps instead? Download the skill ZIP from the GitHub releases page and upload it under Skills.

See all 30 agent skills →

model-file-guard compared with alternatives

OptionHow it differs
picklescanBlocklist; 15 of 23 attacks flagged in our corpus
fickling17 of 23 flagged, 4 false alarms on 5 benign files
modelscan, JFrogBroader platforms; model-file-guard is allowlist-based with zero dependencies

Based on public documentation and our own test files. Each project has different goals; try them on your own data.

Questions about model-file-guard

Can a machine learning model file contain a virus?

Yes. Pickle-based files (.pkl, .joblib, and PyTorch .pt, .pth, .bin and .ckpt files) can tell Python to import and run any function while loading, such as a shell command. Security researchers have found such files on public model hubs. Formats like safetensors, GGUF and ONNX store only data and cannot do this, though malformed headers can still crash a loader.

Is torch.load safe now?

Since PyTorch 2.6, torch.load uses weights_only=True by default, which only allows tensors and plain data. That is a big improvement, but versions up to 2.5.1 could still be tricked (CVE-2025-32434), and many projects still pass weights_only=False to load whole models. Scanning first and saving weights as safetensors is the safest route.

How is this different from picklescan?

picklescan blocks a list of known dangerous imports. model-file-guard allows only imports known to rebuild data, tensors or ML library objects, so new tricks are not missed just because nobody listed them. It also reads joblib files with arrays, tar and 7z containers, broken pickles and hidden zip entries. In our test of 23 attack files it flagged all 23; picklescan flagged 15.

Do I need to download a Hugging Face model to scan it?

No. model-file-guard hf OWNER/REPO reads only the parts of each file it needs, using HTTP range requests. For a safetensors file that is usually the first megabyte.

What does REVIEW mean?

The file needs Python code that is not on the allowlist, usually a model class from your own project. Check that the listed imports are yours, then allow them with --allow.

UN Sustainable Development Goals

How each tool maps to SDG targets →

Want this set up and tuned for your store?

The tools are free. If you would rather have the checks run, the findings fixed and the results measured for you, that is what I do for clients.