Safeguard
AI Security•

Are TensorFlow models code? Why untrusted models need a sandbox

TensorFlow's security guidance says a model is a program, so an untrusted model equals untrusted code. Here is what that means and how to isolate one.

Safeguard Security Team
3 min read

Yes, in the sense that matters for security. TensorFlow's security policy says models are expressed as programs that TensorFlow executes, so using untrusted models or graphs is equivalent to running untrusted code. If you must run one, the guidance is to do it inside a sandbox.

Why a model is more than numbers

It is tempting to picture a model as a table of weights. A saved TensorFlow model also describes a computation graph: a set of operations, wired together, that the runtime carries out. An operation can read files, call other operations and in some cases reach outside the process.

That is the reason the project's guidance puts models in the same bucket as scripts. PyTorch's security policy uses almost the same sentence, saying running untrusted models is equivalent to running untrusted code and recommending a secure, isolated environment such as a sandbox.

What this changes in practice

Old habitBetter habit
Download a model, load it on a dev laptopLoad unknown models in a throwaway container
Run inference with the service account that has cloud accessGive the inference process no credentials it does not need
Treat model files as data in storageTrack them as artifacts with source and hash
Review packages, skip modelsReview both

What a sandbox should look like

A sandbox for model evaluation does not need to be fancy. The goal is to limit what a malicious or buggy model can reach.

  1. A container or VM that is destroyed after use.
  2. No mounted home directory. Copy in only the model and test data.
  3. No cloud credentials and no access to the metadata service.
  4. Restricted network. Block outbound traffic unless the test needs it.
  5. Resource limits on CPU, memory and runtime so a bad model cannot stall the host.
  6. A non-root user inside the container.
docker run --rm --network none --read-only \
  -v "$PWD/model:/model:ro" my-eval-image python eval.py

That example is a starting point. Adjust it for your runtime and your risk.

The multi-tenant case

The TensorFlow guidance calls out the scenario where a service runs models supplied by different users. In that case it recommends sandboxing the model execution. If your platform lets customers upload models, this is the control that decides whether one customer's model can touch another's data.

Do not forget the packages

Isolation handles the model. The environment around it still has packages with their own advisories, including the framework itself. Keep an inventory and update on a schedule. See our guide to dependency risk in ML projects for a starting method.

Where Safeguard fits

Safeguard provides SBOM generation and dependency scanning for the packages in your ML stack, plus reachability analysis and policy gates in pull requests. You can try a free scan at gold.safeguard.sh/scan.

Quick check

Is a model from a well known source exempt from this advice?

The guidance is about untrusted models. A known source with a verified origin lowers the risk, but a sandbox is cheap insurance for first time loads.

Does a sandbox replace dependency updates?

No. It limits the damage from one class of problem. You still need to patch the framework and libraries.

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.