← Learn / Notebooks

AI securityTechnicalStudy guide

Model Supply Chain: Safe Loading and Provenance

Separate tensor format, executable code, pinned revisions and checksum checks in a model artifact review.

Before you start: Files, hashes and the idea that loading software can execute code.

AI-assisted study notebook · Published 14 Nov 2026. Source-support checks and synthetic examples are recorded; automated review is not independent expert fact verification.

In [1]: Architecture

1. Architecture and scope

A model artifact can include weights, configuration, tokenizer files and executable loader code. Safetensors is designed for tensor storage, while Python pickle can execute arbitrary code during unpickling. A data-focused tensor format addresses one loading path; it does not make accompanying Python code trustworthy. [1] [2] [3]

The Hugging Face loading guide describes explicit opt-in for custom model code and recommends selecting a specific revision. Separately, a checksum can show that bytes match an expected digest. If the expected digest comes from the same compromised place as the file, equality alone does not establish who produced those bytes. [3] [4]

Scope. A local artifact-review decision model and harmless byte hashes. No model is downloaded, deserialized or executed.

Workflow and scope notes
  1. Identify artifact. Record where the artifact came from and which files will be consumed. A display name or filename is not a complete provenance record.
  2. Fix version. Select a specific revision and obtain a trusted expected digest. A moving branch can change; pinning still does not prove the chosen revision benign.
  3. Review load path. Inspect whether deserialization or custom code can execute behavior. Tensor data and accompanying executable code require separate analysis.
  4. Controlled review. Compare digests and apply the declared local review policy. The toy’s best outcome remains a candidate for controlled review, never guaranteed safe.
In [2]: Experiment

2. Artifact review decisions

Toggle four declared facts. A digest mismatch stops the toy workflow. Pickle or custom code requires code-execution review. An unpinned revision needs provenance review. Otherwise the result is a candidate for controlled loading review.

Artifact review decisions

Original synthetic experiment · Change an input to update the figure.

The outcome is an author-defined review policy, not a malware detector, signature verifier or safety certification. The example’s digest is calculated over literal local bytes; no external artifact is opened.

Artifact review checks and policy resultCandidate for controlled review. Hash mismatch dominates this declared policy; custom code remains executable regardless of tensor format.Digest matchesYesSpecific revisionYesTensor loading pathYesCustom code absentYesCandidate for controlled reviewThese checks inform review. None certifies the artifact as safe.
Candidate for controlled review
Calculation record
{
  "inputs": {
    "format": "safetensors",
    "custom": "no",
    "pinned": "yes",
    "hash": "yes"
  },
  "outcome": "Candidate for controlled review"
}
CaseResultInterpretation
Digest mismatchStopDo not treat a file with unexpected bytes as the reviewed artifact.
Pickle or custom codeCode-execution reviewPinning and digest equality do not remove executable behavior.
Pinned data-only path; digest matchesCandidate for controlled reviewAuthenticity, loader behavior and downstream model behavior remain separate questions.
In [3]: Interpretation

3. Interpretation and limitations

Python’s warning is about what unpickling can execute. Renaming a pickle file does not change that behavior. The format control describes the actual loading path assumed by the toy, not the file extension. The displayed code hashes bytes and never deserializes them. [2]

The 2023 safetensors audit announcement explicitly acknowledges that absence of flaws cannot be proved. That historical review is evidence about a specific review effort, not a promise about all future versions or all content shipped beside weights. The diagram keeps executable custom code on a separate review lane. [1] [3]

Editorial artifact record: publisher identity, immutable revision, exact file list, expected digests and their trusted origin, loader version, custom code review and intended execution boundary. A checksum comparison supports byte identity under its assumptions; it does not evaluate model behavior or licensing. [3] [4]

Practice exercise

Keep safetensors selected and turn custom code on. Explain why that changes the review outcome even when the revision is pinned and the bytes match. Then change only the digest result and describe the first failing boundary.

In [4]: Python

4. Worked Python example

The core calculation below uses only the Python standard library. The full download adds the verification assertions and input fixtures. It runs locally on synthetic data; it does not load a model or contact a service.

lab.py · Core example · Python 3.13
from hashlib import sha256
from itertools import product


def review(format, custom, pinned, matches):
    if not matches:
        return "Stop: digest mismatch"
    if format == "pickle" or custom:
        return "Code-execution review"
    if not pinned:
        return "Provenance review"
    return "Candidate for controlled review"


# Hash literal bytes only. No loading, unpickling or remote execution.
payload = b"synthetic tensor bytes for notebook only"
expected = sha256(payload).hexdigest()
assert sha256(payload).hexdigest() == expected
assert sha256(payload + b"changed").hexdigest() != expected

Download full Python example and checks ↓

Run: python -I lab.py. Recorded run: Python 3.13; 16 fixture states plus scenario assertions passed. The JSON output is a reproducibility record, not a real-system benchmark.

In [5]: Knowledge check

5. Questions and explanations

Predict before opening the explanation. Answers refer to the stated scope and synthetic inputs.

Q1 · FormatWhat can malicious pickle data do during unpickling?
What can malicious pickle data do during unpickling?
Answer and explanation

Answer: Execute arbitrary code. The Python documentation explicitly warns about arbitrary code execution. [2]

Q2 · ChecksumDoes a matching digest by itself authenticate the publisher?
Does a matching digest by itself authenticate the publisher?
Answer and explanation

Answer: No. It shows byte agreement with an expected value; the origin of that expected value still matters. [4]

Q3 · CodeDoes a tensor format remove risk from accompanying custom Python code?
Does a tensor format remove risk from accompanying custom Python code?
Answer and explanation

Answer: No. The loader may execute code separately from reading tensor data. [3]

Q4 · OutcomeWhat is this toy’s most permissive outcome?
What is this toy’s most permissive outcome?
Answer and explanation

Answer: Candidate for controlled review. The policy is a review aid and makes no safety guarantee.

In [6]: Sources

References and source links

  1. Hugging Face / EleutherAI / Stability AI authors. (2023). 🐶Safetensors audited as really safe and becoming the default.https://huggingface.co/blog/safetensors-security-audit
  2. Python Software Foundation. (Python 3.13.18 documentation). pickle — Python object serialization — Python 3.13.18 documentation.https://docs.python.org/3.13/library/pickle.html
  3. Hugging Face maintainers. (Transformers v5.5.2). Loading models · Hugging Face.https://huggingface.co/docs/transformers/v5.5.2/en/models
  4. Python Software Foundation. (Python 3.13.18 documentation). hashlib — Secure hashes and message digests — Python 3.13.18 documentation.https://docs.python.org/3.13/library/hashlib.html
Source checks and provenance

Primary publisher pages and relevant passages checked on 13 Nov 2026. Source support is not independent expert fact verification. Main documentation can change; retrieved-body hashes, dates, version labels and saved revision IDs are in the audit download.

[1] 🐶Safetensors audited as really safe and becoming the default

Evidence: What is safetensors?; The security audit. A historical audit report announcement; not a guarantee for every version, model or loader.

Public ResearchNode original e9409320abb4181ca2f3cd5138dfebe9
Revision 8ddc8d11334f7341d1088ee1fbb9e4b3. Captured 2026-11-06.

[2] pickle — Python object serialization — Python 3.13.18 documentation

Evidence: Warning at the start of pickle documentation. The example never imports pickle or deserializes external bytes.

[3] Loading models · Hugging Face

Evidence: Custom models. Remote custom code and revision selection are separate from the tensor storage format.

[4] hashlib — Secure hashes and message digests — Python 3.13.18 documentation

Evidence: Hash algorithms; Usage. A digest checks bytes against a trusted expected value; publisher authenticity requires a separate trust decision.

Claim-to-evidence ledger ↓ · Review report ↓