Safeguard
AI Security•

Is it safe to load a scikit-learn joblib or pickle model file?

Only load a joblib or pickle model from a source you trust. scikit-learn's own docs say so. Here are safer formats, version rules and a quick checklist.

Safeguard Security Team
3 min read

Only if you trust where the file came from. scikit-learn's documentation says pickle, and joblib and cloudpickle by extension, have documented security vulnerabilities by design and should only be used with files from a trusted, verified source. Treat loading a model file like running a program.

Why loading can run code

A pickle file is not just data. It is a set of instructions that rebuild Python objects when loaded, and those instructions can call functions. A file crafted by someone else can make that rebuild do something harmful. The scikit-learn page compares loading an untrusted pickle with executing code from an untrusted source. For the general case, see Python pickle with untrusted data.

The alternatives scikit-learn names

FormatWhat it gives youCost
ONNXNo Python object is loaded, so no pickle pathNot every model converts, custom parts need work
skopsReturns the Python object without allowing arbitrary code by defaultSlower, fewer types than pickle
pickle or joblibFast, widest supportTrusted sources only

For skops, the documentation shows a step where you list untrusted types in the file and load only if you trust everything in it. The page also notes that ONNX is not automatically safe, since it can represent arbitrary computation, and recommends serving such models in a sandboxed environment.

The version rule that surprises people

The documentation says there is no supported way to load a model trained with a different scikit-learn version. It may load but is described as entirely unsupported and inadvisable, and results may be wrong or the process may crash. It recommends pinning scikit-learn, NumPy, SciPy and related packages the same in training and production, and using containers to freeze the environment.

That is a supply chain point as well as a reliability point: a pinned, scanned environment is easier to reason about than a loose one.

A checklist before you load a model

  1. Know who produced the file and how it reached you.
  2. Compare a checksum with one published through a separate channel.
  3. Load it in a container with no secrets and no network.
  4. Prefer a format that does not execute code when you have the choice.
  5. Save metadata with your own models: training data reference, code, library versions and score.

Try it yourself

Click through it at your own pace, or open it full screen. See how reachability separates vulnerable code that runs from code that never does.

Quick check

Is joblib safer than pickle?

No. The documentation says the same limits apply to joblib and cloudpickle.

Can I load a model from a newer scikit-learn version?

It is described as unsupported and inadvisable. Retrain or pin the same version.

Safeguard's reachability analysis helps show which vulnerable code your project actually calls, and a free scan covers dependencies.

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.