Detecting malicious pickle and PyTorch models with ModelAudit

Pickle and PyTorch model files can execute code when they are loaded. This page explains how ModelAudit scans them before use, what it flags, what a clean scan does not prove, and which formats to require from model suppliers.

On this page

How malicious pickle and PyTorch models reach your environment

A team that is about to load a pickle or PyTorch model from a supplier, a model hub or an internal registry is accepting code along with the weights. ModelAudit, the model file scanner included in promptfoo, reads the structure of pickle streams and PyTorch files and flags patterns that can run code when the file is deserialized. Intake scanning is needed whenever a model file arrives from outside the team that will load it, including files re-uploaded to an internal bucket, because the file's origin is often the only trust signal a team has before loading. promptfoo is licensed under the MIT license, and its introduction documentation describes the software as running locally, so the scan can run on a host you control inside your own network.

Treat static scanning as one input to an accept or reject decision, and do not treat a clean result as proof of safety. Flags come from known patterns, so a file can pass a scan and still contain behavior the rules do not cover, while a finding may also be a false positive that a person has to review. Decide in advance who may override a finding, what a rejection looks like in the intake record, and which findings always block loading. Ask the supplier to confirm the file format, the framework version used to save the file, and whether the weights are stored in a format that does not carry an executable pickle payload. A pickle file from an unknown source is a higher-risk intake than a file from a source your team already reviews.

Write the intake decision down where the next person can find it. The record should name the source, the file hash, the scanner version, the command or configuration used, the findings and the reviewer who accepted or rejected the file. Confirm the scanner version against the current release before you rely on it. At the time of writing, the promptfoo npm package was at release 0.124.1, published on 8 October 2026, and it requires Node.js 22.22.0 or newer, so the intake host needs that runtime. Ask your security and ML leads to agree on the rule before the first model arrives, because a team that decides under deadline often loads the file first and scans it later.

How a model file moves from supplier to approved use

The flow starts at the model supplier or hub, outside your trust boundary. The file is transferred into a quarantine location inside your boundary, where nothing loads it yet. ModelAudit scans the quarantined copy, and a reviewer works through the findings before deciding. Only accepted files move to the load environment. Rejected files go back to the supplier, and the supplier should be told why. Before loading, confirm that the file in the load environment matches the scanned copy, for example by comparing checksums.

Model intake path, with the trust boundary and reject path shown.

Why pickle can run code when a PyTorch model loads

Pickle rebuilds objects by running a sequence of opcodes against a stack, a simple machine where values are pushed, combined and popped. Some opcodes import named callables. GLOBAL and STACK_GLOBAL load an attribute from a module, such as a function or class, and REDUCE then calls that callable with arguments pushed earlier on the stack. Nothing in this process checks whether the callable is safe to run. A crafted file can therefore name a function from any module importable in the loading environment and call it with chosen arguments while the file is still loading, before your application inspects the result. For a team deciding whether to accept a model, the practical point is that loading an untrusted pickle means running code chosen by its author, with the permissions of the process that loads it.

PyTorch model files have historically used pickle for their object data, so a checkpoint loaded with torch.load carries the same behavior. PyTorch's standard save format is a ZIP archive. The object structure sits in a pickle entry, usually named data.pkl, and tensor contents sit in separate records beside it. A scanner that reads only the outer file or the tensor data misses the instructions that matter, so ModelAudit has to open the archive and analyze the pickle entries inside it. Confirm the loading defaults for each PyTorch version your teams use, including whether torch.load restricts unpickling by default and how the weights_only setting behaves, because those defaults can change between releases and they determine how much protection a loader gives you before a scan runs.

For model intake, treat any pickle-based file as code until it has been scanned, and decide which formats suppliers may send before the first file arrives. Ask suppliers whether they can provide weights in SafeTensors, a format that stores tensors without executable object instructions, and record the answer in the intake record. Where pickle remains necessary, load the file only in an isolated environment with no credentials and no route to production systems, and tie the scan result to the exact file hash so a later copy cannot inherit an earlier approval. A clean scan supports the accept decision, and the isolation step remains the control that limits damage if the scan missed something.

Which patterns ModelAudit flags in pickle, PyTorch ZIP and binary files

ModelAudit reads model files without running them and reports patterns that suggest code would execute when the file is deserialized. The five families below cover the pickle layer, the PyTorch archive that wraps it, and any binary file whose contents do not fit its extension. Each flag is a lead for review and needs a decision from someone who knows where the file came from.

Imports of system-level modules

A pickle stream can name a module and a callable, and the loader resolves that name while it reads the file. ModelAudit flags imports from system-level and code-execution modules, such as operating system, shell and interpreter libraries, because those names let a file reach the host during load. Any such import in a weights file needs an explanation before the file is accepted. Check each flagged module against the rule list in the ModelAudit documentation for your installed version.

Opcodes that call imported callables

An import only places a name within reach. An opcode that then calls that callable with arguments is what turns the reference into an action during deserialization. ModelAudit reports these call-style opcodes, and the finding is strongest when a call targets a name flagged by the import check. Review the import and the call together, because a call to an ordinary helper may be benign while the same opcode aimed at a shell function is a serious finding. Confirm the opcode list for your installed version in the ModelAudit documentation.

Suspicious content in PyTorch archives

A current PyTorch checkpoint is usually a ZIP archive that holds a pickle record plus raw tensor storage entries. ModelAudit inspects those entries and flags content the expected layout does not account for, such as extra pickle records or entries sitting outside the tensor data. Compare every entry against the layout for the checkpoint's format version. A reviewer should also ask whether the archive came from a training run the organization can trace.

Nested or obfuscated pickle payloads

A payload can hide its import inside another pickle, inside an encoded byte string or behind a decoding step, so a plain text search misses it. ModelAudit looks for nested streams and obfuscation patterns that suggest the loader would rebuild code at runtime. A second layer of serialization is hard to justify in a weights file, so ask the supplier why it is there. Confirm which nesting and encoding checks your installed version performs, since coverage varies by release.

Binary files that mismatch their format

A file named as one format but built like another can carry a payload past a loader that trusts the extension. ModelAudit compares the leading bytes and structure of binary files against the format they claim to be, and flags files whose content does not match. Treat a mismatch as a rejection until the supplier explains it, since a correct export has no reason to disagree with its own extension. Check the format checks and their scope in the ModelAudit documentation for your version.

Ways to run ModelAudit scans and when each fits

This table compares four ways to run ModelAudit scans, from a single command on one file to a gate in a delivery pipeline. Read each row for the situation it suits and the trade-off that affects who can run it and how results reach reviewers. Confirm which interfaces your installed version exposes before you commit to a workflow.

OptionFits whenMain trade-off
Standalone commandOne engineer checks a single file or a directory of downloaded model files before it is loaded.Results stay on the machine that ran them. Sharing means exporting output, and nothing enforces the decision.
promptfoo CLIA team wants scans run from the same tool it uses for evals and red teaming, with output saved to files it can keep.Access depends on each workstation or runner. Results still need a manual handoff to reviewers.
promptfoo web UIReviewers want to read findings, compare scans and record a decision without opening raw output.Self-hosted server uses local SQLite, has no RBAC or built-in SSO, and is not recommended for production use.
Pipeline gateModel changes need a repeatable pass or fail result before they reach a registry or deployment.Gate results depend on the runner's access to model files and on how failures are triaged. Confirm exit code behavior in your version.
Confirm before choosingCheck which interfaces your installed version exposes, since standalone, CLI and UI support can differ by release.Ask the vendor or read the release notes for the version you plan to pin, and record that version in your intake procedure.

Setting up ModelAudit scans for pickle and PyTorch intake

This sequence produces a scanning setup that your team can run the same way every time, from runtime checks to recorded decisions. It ends with a fixture set that shows each flag family is detected, an accept or reject rule the security owner has approved, and a decision record that names the scanner version. Complete it before any supplier model reaches a production path.

  1. Confirm the Node.js runtime version

    The platform engineering lead confirms that the Node.js version on the scanning host meets the requirement of the promptfoo npm release you plan to pin. Release 0.124.1, published on 8 October 2026, requires Node.js 22.22.0 or newer, so check each host with node --version and record the output. Run the check on the same image or host type that will perform intake scans, since build agents often differ from engineering workstations. The step is done when every host that will run scans reports 22.22.0 or higher.

  2. Install promptfoo in an isolated environment

    Install the promptfoo npm package, pinned to release 0.124.1, in a dedicated container, virtual machine or project directory used only for model intake. Keep this environment apart from training pipelines and from any service that loads models, so a scanner fault cannot reach production credentials. Review the promptfoo package listing on npm to confirm the install path, and confirm how ModelAudit is invoked through your chosen install method. The step is done when the package manager output shows 0.124.1 and the lockfile is committed to the intake repository.

  3. Build benign fixtures for each flag family

    The security engineer builds a fixture set inside an offline sandbox with no network access and no copies of actual malicious files. Each fixture is an inert pickle or PyTorch ZIP archive that triggers one flag family in ModelAudit, such as a suspicious opcode pattern, an unsafe global reference or an archive with unexpected members, without carrying a working payload. Include one clean control file that should produce no findings. The security owner reviews each fixture and its expected result. The step is done when every flag family you intend to gate on has at least one fixture with a documented expected result.

  4. Run baseline scans and compare results

    The security engineer runs ModelAudit over the full fixture set using the pinned install and saves each report in a machine-readable format the scanner supports. Confirm the output options in the scanner documentation before you script the run. Compare the output with the expected-result table from the previous step, fixture by fixture. If a fixture fails to trigger its family, or the control file produces a finding, the scanner setup or the fixture is wrong, so fix the gap before continuing. The step is done when every fixture matches its expected result and the baseline report is committed alongside the fixtures.

  5. Agree the accept or reject rule

    The security owner and the intake lead agree in writing which findings reject a model outright, which send it to manual review, and how formats the scanner cannot fully inspect are handled. Tie each rule line to a flag name and fixture result from the baseline run, so every rule has evidence behind it. Document who may override a rejection and what evidence an override requires. Store the rule in version control so later changes are visible. The step is done when the security owner has approved the rule in writing and every rule line cites a baseline result.

  6. Record the scanner version with each decision

    Every accept or reject decision is written to a record that includes the promptfoo release (0.124.1 for this pin), the Node.js version, the ModelAudit findings, the file checksum, the version of the accept or reject rule, and the name of the approver. An auditor can then trace which scanner and rule produced each outcome. Sample one recorded decision and re-run the scan on the pinned version to confirm the findings reproduce. The step is done when a sampled record can be re-run from its stored versions and produces the same findings.

Safer formats to require from PyTorch model suppliers

When a team is about to bring a new model into its environment, the cheapest control is to set the format requirement before the first file arrives. Ask for weights in a format that stores tensors and metadata without loading a pickle object, and make that a gate in the intake checklist that every model must pass before anyone loads it.

  • Non-executing format first: Request SafeTensors weights where the supplier offers them, and check the file extension and format header during intake.
  • Accepted formats in the request: Put the accepted formats in the model request template so the supplier knows the rule before packaging.
  • Scan before first load: Run ModelAudit on any file in a pickle or PyTorch ZIP container, even when the supplier describes it as safe.
  • Recorded checksum: Store the hash of the accepted file so later copies can be compared with the version that was scanned.
  • Separate conversion review: If a model is only available as a pickle file, plan the conversion as its own task with its own review and approval.

Conversion steps and compatibility depend on the model and framework version, so confirm both before approving intake. The sibling guidance on scanning GGUF, SafeTensors and ONNX models covers the format-specific checks.

Security and operational considerations for model file scanning

A scan verdict only holds for the file and the scanner that produced it. The controls below keep that verdict trustworthy: when the scan runs, where the candidate file sits, which scanner version made the call, and how the result is kept for later review.

Scan before any load

A pickle file runs its instructions when it is deserialized, so the scan has to finish before any framework call, such as torch.load or a pickle load, touches the file. Make the scan a gate in the intake step. Check that notebooks, training jobs and serving images read only from the approved location, and that no job opens a downloaded file before its scan result is recorded. Without this gate, a malicious checkpoint can run code during the first experiment that opens it.

Quarantine scans without production credentials

Run the scan in a quarantine location that holds the candidate file and nothing else. The scanning host should have no production cloud roles, registry write access or model-serving secrets, and the quarantine path should not be mounted into any serving or training system. Treat the scan host as the first place an untrusted file lives. Without this separation, a compromised scan job can reach credentials that matter or overwrite artifacts that other teams rely on. Confirm the isolation with your platform team before the first scan.

Pin scanner version and rules

Record the promptfoo version that ran the scan, the Node.js version beneath it and the ModelAudit settings you applied. A verdict only holds for the scanner that produced it. Pin the version in your intake tooling and change it through review, the same way you handle other security tooling. Check the release notes to see what changed between versions. Without a pinned version, the same file can pass one week and fail the next after an upgrade, and nobody can reconstruct why an earlier accept decision was made.

Promptfoo releases

Hash every model file

Compute a SHA-256 hash of each model file before the scan and store it with the report. The hash ties a verdict to exact bytes. File names, repository tags and version labels can all change after an approval, so a checkpoint can be replaced under the same name. Before any load, compare the file's current hash with the recorded one. Without this check, an accepted model can be swapped for an unscanned copy that carries the original name, and the old report will still say it passed.

Choose where results live

promptfoo runs locally on the machine where it is installed, so scan results stay on that machine unless your team moves them. Decide the storage location, who can read the results, how long they are kept and who signs off on the decision before the first scan. A report on one laptop cannot serve as an audit trail. Self-hosted promptfoo uses a local SQLite database that cannot be shared across replicas, so a team with several users needs a deliberate storage plan. Without one, results vanish with a reimaged machine or stay out of reach of the reviewer.

Self-hosting docs

Rescan on scanner or model change

Rescan when the promptfoo version or rule settings change, and when a model file changes by hash, revision or source. An accept decision expires when either input changes. Keep a list of accepted hashes and rerun the scan against that list when the scanner moves forward, so a file approved under older rules gets a fresh verdict. Schedule periodic rescans of stored models as well. Without this step, a model accepted months earlier stays in use after the scanner gains a new check, and nothing prompts anyone to look again.

What a clean ModelAudit scan does not establish

A clean ModelAudit scan establishes less than it appears to. It shows that the checks ModelAudit ran did not match anything in the parts of the file they could read. It does not establish that a model is free of backdoors or unsafe behavior. Poisoned weights carry no code payload for a pickle opcode rule to find, so a model can pass static inspection and still respond differently to specific inputs. Treat a clean result as one input to the intake decision, and keep behavioral checks in the process, such as evaluating the model against your own test prompts before it is approved for use.

Pattern rules only cover constructs their authors have already seen, so a novel payload that uses an unlisted callable or an unusual encoding may pass without a finding. The reverse also happens: a flagged file may be a false positive, for example a legitimate custom class reference that matches a rule written for something else. Each flag needs a named reviewer who checks the source, the loading code and the supplier's explanation, and records the decision against the file hash. Before relying on the tool, confirm in the ModelAudit documentation which formats it supports, how it handles nested or compressed archives, and what resource limits apply to large files. Then test those answers against your own set of known-benign and known-malicious samples, including archive-wrapped and oversized files.

DeployOpen can help plan and test this intake process in your environment, and prepare the evidence your teams need to review it. DeployOpen does not issue audit reports, attestations or certifications. Independent auditors and certification bodies issue those, and they decide what a scan record is worth in an assessment. Ask your auditor early which scan records, reviewer decisions and retention periods they expect to see, and confirm that the ModelAudit runs cover every model source they will examine.

What teams ask before adding pickle and PyTorch model scanning

How much does it cost to add pickle and PyTorch model scanning?

The promptfoo license is MIT, and the promptfoo package on npm is free to obtain, so the cost is the effort to integrate, test and operate scanning. That effort has four parts: connecting scans to your model storage and pipelines, setting the accept or reject policy, triaging findings, and keeping the tooling current. The first two are mostly one-time work. The last two recur as model volume and the number of pipelines grow. Costs rise with the number of model sources, the variety of formats, the number of gates that must block a load, and how many findings need manual review by people with model context. When you request a quote, ask it to separate one-time integration from recurring operation, and to state who performs each part: your team, a partner, or both.

How long does it take to set up model file scanning?

Setup time depends on the intake you already have, so it should be stated in a written plan rather than assumed from a template. The main drivers are the number of model sources (public hubs, object storage, a model registry, internal training output), whether scans must run in CI/CD pipelines, how many file formats your teams load, and whether accept or reject decisions need sign-off from security or compliance. Environment limits also matter. The current npm release requires Node.js 22.22.0 or newer, and access to model stores usually needs network approvals and credentials managed through your own secrets process. Large model files and air-gapped networks add testing time. Ask for a timeline tied to a written scope that lists sources, formats, pipelines and approvers.

What does our team need to provide for a model scanning project?

Your team supplies the context that a scanner cannot infer on its own. Expect to provide:

  • An inventory of model sources, storage locations and the formats each team loads
  • A non-production environment with Node.js 22.22.0 or newer, plus access to the model stores in scope
  • A named owner for accept or reject decisions and for exceptions, with escalation contacts
  • Sample files, including known-good models and any suspicious files found during intake, for testing scanner behavior
  • Documentation of current model loading paths, so the team knows which services would be affected by a rejected file

The owner also needs time to review findings during the test period, because the first runs usually surface files that need a decision.

Can our own engineering team set up model scanning alone?

A capable engineering team can install the package and run scans without a partner, because the license is MIT and the tooling is free to obtain. The harder work is usually organizational. Someone must decide which formats and findings block a load, write that policy so decisions stay consistent, wire scans into pipelines so they fail visibly, and keep the setup working through version changes. Teams often bring in an outside partner when they lack time to build those pieces, when the intake must be reviewed by an independent party, or when scanning must fit into a wider model review. Confirm your team's capacity for the policy and pipeline work before you decide, since the install is the smallest part of the effort.

Does pickle scanning replace a security review of AI models?

No. Static scanning checks model files for patterns that can run code when they are loaded, such as suspicious pickle opcodes. It does not establish where a model came from, whether the training data and license allow your use, or how the model behaves under adversarial prompts. Those questions need provenance records, license review and behavioral testing, where promptfoo red teaming can help. Treat a clean scan as one input to the decision and a flagged file as grounds to reject or investigate. DeployOpen can prepare the systems, controls and evidence that a compliance assessment asks for, but independent auditors and certification bodies issue any report or certification.

How is a fixed-scope quote for model scanning produced?

DeployOpen agrees scope, deliverables and timelines in writing before work starts, and the quote follows from that written scope. DeployOpen does not publish a price list. To compare quotes fairly, define the model sources and formats in scope, the pipelines or registries to integrate, the testing expectations for flagged and missed files, the documentation and handover, and any recurring support. Ongoing support, upgrades and continuous testing are available as retainers, so ask for recurring work as a separate line. A useful proposal lists each deliverable, the environment it runs in, what the client provides, and what is excluded.

What should our engineers check when a model scan flags a file?

Treat the flagged file as untrusted and keep it out of every loader, including notebooks, training jobs and serving containers. Read which opcode or pattern triggered the finding, then decide whether the file's origin explains it. Compare the file with the publisher's official release and any published checksum. Ask the supplier for a safer format, such as SafeTensors, where the model allows it. Record the finding, the decision, the scanner version and the approver, then rescan after any change to the file or the policy. Confirm with the scanner's documentation how each finding type is reported before you build alerts on it.

How DeployOpen scopes and delivers model file intake scanning

DeployOpen scopes model file intake scanning as a fixed-scope piece of work, so the boundaries, the model formats in play and the acceptance rules are agreed in writing before any scanner runs. We then install and configure ModelAudit in infrastructure you control, wire it into your intake steps, and hand over the decision rules and runbooks your teams will use. Support after handover is available as a retainer.

How we scope

  • The written scope lists the pickle, PyTorch ZIP and binary formats in scope and where those files come from.
  • It defines which intake points are covered, such as a download folder or a registry.
  • It sets the accept, reject and manual review outcomes and who signs off on each one.

How we build

  • We install ModelAudit in infrastructure you control, either standalone or through promptfoo, matching the approach in your scope.
  • We configure scan settings for pickle and PyTorch files, including how suspicious opcodes and patterns are reported.
  • We connect the scan to your intake step, then test it with sample files agreed in the scope.

How we hand over

  • Deliverables include the installed scanner configuration, the intake procedure and the accept or reject decision rules.
  • Runbooks explain how staff read a flagged pickle or PyTorch result and what to escalate.
  • Documentation records the scan version, the rule settings and the evidence each intake decision produces.

How we support

  • Ongoing support covers keeping ModelAudit and its configuration current in your environment, available as a retainer.
  • Retesting follows changes to scan settings, intake sources or the promptfoo version you run.
  • Support can extend the intake procedure when new model formats enter your supply chain, under a written change.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.