huggingface/smolagents · error · ValueError
Loading an agent from Hub requires to acknowledge you trust
Error message
Loading an agent from Hub requires to acknowledge you trust its code: to do so, pass `trust_remote_code=True`.
What it means
from_hub downloads and executes arbitrary agent code from a Hugging Face Space. As a safety gate, it refuses to proceed unless trust_remote_code=True is passed, mirroring transformers' trust_remote_code convention. The error is purely an acknowledgment check, not a network or auth failure.
Source
Thrown at src/smolagents/agents.py:1098
</Tip>
Args:
repo_id (`str`):
The name of the repo on the Hub where your tool is defined.
token (`str`, *optional*):
The token to identify you on hf.co. If unset, will use the token generated when running
`huggingface-cli login` (stored in `~/.huggingface`).
trust_remote_code(`bool`, *optional*, defaults to False):
This flags marks that you understand the risk of running remote code and that you trust this tool.
If not setting this to True, loading the tool from Hub will fail.
kwargs (additional keyword arguments, *optional*):
Additional keyword arguments that will be split in two: all arguments relevant to the Hub (such as
`cache_dir`, `revision`, `subfolder`) will be used when downloading the files for your agent, and the
others will be passed along to its init.
"""
if not trust_remote_code:
raise ValueError(
"Loading an agent from Hub requires to acknowledge you trust its code: to do so, pass `trust_remote_code=True`."
)
# Get the agent's Hub folder.
download_kwargs = {"token": token, "repo_type": "space"} | {
key: kwargs.pop(key)
for key in [
"cache_dir",
"force_download",
"proxies",
"revision",
"local_files_only",
]
if key in kwargs
}
download_folder = Path(snapshot_download(repo_id=repo_id, **download_kwargs))
return cls.from_folder(download_folder, **kwargs)View on GitHub (pinned to 30bb116109)
Solutions
- Pass trust_remote_code=True: MultiStepAgent.from_hub('user/agent-space', trust_remote_code=True).
- Only do so after reviewing the Space's code, since it will execute on your machine.
- If you cannot trust the code, vendor the agent files locally, audit them, and load via from_folder.
Example fix
# before
agent = MultiStepAgent.from_hub('smol-agent/best-agent')
# after
agent = MultiStepAgent.from_hub('smol-agent/best-agent', trust_remote_code=True) Defensive patterns
Strategy: validation
Validate before calling
agent = MultiStepAgent.from_hub(repo_id, trust_remote_code=True) # only after auditing the Space's code
Prevention
- Review the Space's agent code before passing trust_remote_code=True.
- Pin the exact repo revision via the `revision` kwarg for reproducibility.
- For untrusted sources, download, audit, and use from_folder instead.
When it happens
Trigger: Calling MultiStepAgent.from_hub('username/space-name') or from_folder on a Hub-downloaded agent without passing trust_remote_code=True.
Common situations: Following a Hub model card example and forgetting the flag; CI scripts that load shared agents; copying from_hub code from older tutorials written before the flag existed.
Related errors
- Forbidden access to module: {result.__name__}
- Forbidden access to module: {result['__name__']}
- Forbidden access to function: {function_name}
- Forbidden access to dunder attribute: {expression.attr}
- Invoking a builtin function that has not been explicitly add
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/38d091ef17029127.
Report an issue: GitHub.