Avoid lookalike models by treating the full repository ID, organization and name, as the identity, pinning a commit hash, preferring safetensors weights, and leaving remote code execution off. A model name copied from a tutorial is an unreviewed dependency, so put it in reviewed configuration.
What does confusion look like for models?
In package registries, attackers publish names that sit one keystroke from a popular package. Model hubs have the same shape. A Hub repository is addressed as an organization or user name, a slash and a model name. Two different owners can publish models with near identical names and similar descriptions, and a tutorial, a chat answer or a mistyped string can point at the wrong one.
The harm differs from a bad library, because a model file is data that your code deserializes. If the format can carry code, loading it is running it.
Why is the file format part of the answer?
Hugging Face's own documentation on pickle scanning says pickle is a widely used serialization format in machine learning and the default for PyTorch model weights, and that dangerous arbitrary code execution attacks can be carried out when you load a pickle file. Its stated advice is to load models from users and organizations you trust, rely on signed commits, or use other formats. The Hub shows the list of imports found in a pickled file, which helps you spot a model that calls system functions.
Safetensors is a format designed for storing tensors only, and the project describes it as a simple alternative. Preferring it removes a whole class of surprise from loading.
What about remote code?
In the Transformers library, the trust_remote_code parameter allows custom models defined on the Hub in their own modeling files. The documentation lists its default as False. Keep it that way. If a lookalike model includes a modeling file and someone sets the flag to make an error go away, you have executed the author's Python.
Which platform features help?
The Hub supports malware scanning that triggers on each commit, with badges on files and a warning when at least one file is scanned as unsafe. A file with neither an ok nor an infected badge may be waiting or may have hit an error, so no badge is not a pass. The security page also lists commit signatures, two-factor authentication and access tokens. For your own access, the token guidance recommends one token per application and fine-grained tokens for production, and says CI workflows can use trusted publishers with short-lived tokens, so no long-lived token is stored.
What does the revision parameter give you?
The revision argument can be a branch, a tag or a commit id, because the Hub is git based. The default is main, which moves. Pinning a commit hash means a later change to the repository, including a malicious push after an account takeover, does not reach your build.
A constructed example
A team copies from_pretrained("acme-ai/sentiment-small") from a blog. A teammate fixes a typo while refactoring and the string becomes acme-al/sentiment-small, with a lowercase L in place of the letter I. The second repository exists, runs on the test inputs, and loads a pickle file. Nothing fails. A code review rule that model IDs live in one configuration file, with an owner and a commit, would have shown the diff clearly.
What to do
- Move every model and dataset ID into a configuration file, not scattered strings.
- Record the organization, name, commit hash and format for each.
- Require review for changes to that file.
- Prefer safetensors and avoid loading pickle files from sources you have not verified.
- Keep
trust_remote_codeat its default of False unless you have read the modeling code. - Open the repository page, check the owner, history and any scanner badges before first use.
- Use fine-grained or trusted publisher tokens in CI instead of a stored token.
- Add models to your AI bill of materials.
Safeguard's MCP Guardrail and dependency scanning cover related ground for agent tools, see the MCP guardrail demo.
Quick check
Does a clean scanner badge prove a model is safe?
No. Scanning looks for known bad patterns. A missing badge can also mean the scan is pending or failed.
Why pin a commit rather than main?
Main moves. A commit id is fixed, so later changes to the repository do not alter what you load.
Sources
- Hugging Face Hub: Pickle Scanning
- Hugging Face Hub: Malware Scanning
- Hugging Face Hub: Security overview
- Hugging Face Hub: User access tokens
- Transformers documentation: Auto classes
- Safetensors documentation
Last reviewed: 18 October 2026.