Safeguard
AI Security•

Do Hugging Face dataset loading scripts run code on your machine?

Yes. A dataset script is Python. The Datasets library blocks them by default and requires trust_remote_code=True. When to say yes and what to check.

Safeguard Security Team
4 min read

Yes. A dataset loading script is a Python file, and loading the dataset runs it. The Hugging Face Datasets documentation says scripts are not allowed to run by default, for security reasons, and that you must pass trust_remote_code set to True to load datasets that need one. Prefer datasets stored as plain data files.

Two kinds of dataset repositories

Some dataset repositories hold only data files in formats the library already understands, with a description in YAML metadata. Loading those needs no repository code.

Others include a script that defines the configurations and splits and says how to download and process the data. The docs describe the script as a Python file, and note it can download data files from any website. That flexibility is the reason the library asks you to opt in.

What the docs say about the default

The Datasets documentation states that for security reasons the library does not allow running dataset loading scripts by default. To load a dataset that needs a script, you pass the trust remote code option, set to True.

That one argument is a switch from data to code execution. It is easy to type because a tutorial said to, and easy to leave in a copied snippet.

Decision guide

SituationSuggested action
Dataset has data files and a metadata card, no scriptLoad normally
Dataset needs a script, publisher known and reviewedRead the script, pin the revision, load in a sandbox
Dataset needs a script, publisher unknownDo not run it. Ask for data files, or find another source
A tutorial tells you to pass trust remote code with no explanationStop and read what the script does first

How to review a loading script

A script is short enough to read. Spend ten minutes.

  1. Open the Python file in the repository and read the whole thing.
  2. List every URL it contacts. Do they match the data source described on the dataset card?
  3. Look for subprocess calls, shell commands, dynamic imports, evaluation of strings and writes outside the cache.
  4. Check imports for packages you have not heard of, and check that they are real and maintained.
  5. Pin the exact repository revision you reviewed, so a later edit cannot change what runs.
  6. Run it the first time in an isolated environment with no credentials and no network beyond the data host.
datasets.load_dataset("ORG/DATASET", revision="COMMIT_HASH", trust_remote_code=True)

The revision is part of the safety. Reviewing a script and then loading whatever is latest defeats the review.

Catch it in code review

Search your codebase for the option so that every use gets a human decision.

grep -R "trust_remote_code" --include="*.py" .

Add a comment next to each match saying who reviewed which revision and when. A CI check can fail when a new match appears without that comment.

The same habit applies to model loading, where a similar option exists for custom model code. A separate post on this blog explains what that model option runs.

Try it yourself

Click through it at your own pace, or open it full screen. See how a code scan flags risky calls, which is the lens to use on a loading script.

Quick check

Is a dataset without a script safe?

Safer from code execution, not from bad data. Data can still be poisoned or mislabeled, so check provenance and license.

Can I turn the option on globally to avoid errors?

Avoid that. Enable it per dataset, after review, and with a pinned revision.

Where Safeguard fits

Safeguard offers dependency scanning and policies and gates in CI, which can help catch risky settings and vulnerable libraries in your data pipeline code. A free scan is available.

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.