Safeguard
AI Security•

Model file extensions and what each can do: a quick risk table

Which model files can run code when loaded? A quick table for .bin, .pt, .h5, .keras, SavedModel, .onnx and .safetensors, with sources and review advice.

Safeguard Security Team
4 min read

Not every model file is equally risky to open. Pickle based files such as many .bin and .pt checkpoints can run code on load. TensorFlow SavedModel graphs are treated as code. Keras files can embed lambda code. Safetensors holds only tensors. Use the table below to decide how much review a file needs.

The table

File typeTypical extensionCan it run code on load?What the sources say
PyTorch checkpoint.bin, .pt, .pthYes, if loaded as a plain pickleHugging Face calls pickle the default format for PyTorch weights and warns of arbitrary code execution
TensorFlow SavedModelsaved_model folderTreat as yesTensorFlow says untrusted models are equivalent to untrusted code
Keras v3.kerasOnly if unsafe lambda loading is enabledKeras safe_mode defaults to True and blocks unsafe lambda deserialization
Keras legacy.h5Treat with careThe TensorFlow guide lists HDF5 as a legacy format
ONNX.onnx plus data filesNot a pickle, but paths matterExternal data uses relative file paths
Safetensors.safetensorsNo code in the formatHeader plus raw bytes, no pickle

I describe the .h5 row as "treat with care" because the pages I read call it a legacy format and describe Keras safe mode for the v3 format only. They do not give a per format verdict for HDF5, so verify that for your version before relying on it.

How to use the table

  1. List the files in a model repo before loading anything.
  2. For each extension, find its row and decide the handling: trusted source only, sandbox, or normal.
  3. If a repo offers safetensors, prefer it and skip the rest when you can.
  4. For anything marked yes or treat as yes, load only from sources you have decided to trust, inside a sandbox with no secrets and no network.

Files that are not weights

A repository also holds files that are not weight files. Custom model code is the one to watch. In the Transformers library, loading a custom model needs the trust_remote_code option, and the docs advise taking extra precaution and loading from a specific revision so you do not load code that has changed. A weights file can be fine while a Python file beside it is the real risk.

Config and tokenizer files are data, but your loader reads them, so keep them under the same pinned revision as the weights.

Common mistakes

  1. Judging a repo by its weights file alone and never opening the other files.
  2. Assuming a hub scan result replaces review. The Hub's own page says its pickle scan is not foolproof and that the user is responsible for checking.
  3. Switching Keras safe mode off to make a load error go away.
  4. Loading a file on a laptop that holds cloud credentials.

Quick check

Is a .bin file always a pickle?

No, the extension is only a hint. Many .bin weight files from PyTorch are pickle based, but you should check how your loader reads it, not rely on the name.

Is safetensors enough on its own?

It removes the code execution path in the weights file. You still need to check code files in the repo, the license, the source and the behavior of the model.

Safeguard scans repository dependencies and generates SBOMs, and policies and gates can block risky changes in pull requests. Try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.