{"record":{"id":"86f28b1169ac8944","repo":"huggingface/smolagents","slug":"loading-a-tool-from-hub-requires-to-acknowledge-yo","errorCode":null,"errorMessage":"Loading a tool from Hub requires to acknowledge you trust its code: to do so, pass `trust_remote_code=True`.","messagePattern":"Loading a tool from Hub requires to acknowledge you trust its code: to do so, pass `trust_remote_code=True`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/tools.py","lineNumber":550,"sourceCode":"\n        </Tip>\n\n        Args:\n            repo_id (`str`):\n                The name of the Space repo on the Hub where your tool is defined.\n            token (`str`, *optional*):\n                The token to identify you on hf.co. If unset, will use the token generated when running\n                `huggingface-cli login` (stored in `~/.huggingface`).\n            trust_remote_code(`str`, *optional*, defaults to False):\n                This flags marks that you understand the risk of running remote code and that you trust this tool.\n                If not setting this to True, loading the tool from Hub will fail.\n            kwargs (additional keyword arguments, *optional*):\n                Additional keyword arguments that will be split in two: all arguments relevant to the Hub (such as\n                `cache_dir`, `revision`, `subfolder`) will be used when downloading the files for your tool, and the\n                others will be passed along to its init.\n        \"\"\"\n        if not trust_remote_code:\n            raise ValueError(\n                \"Loading a tool from Hub requires to acknowledge you trust its code: to do so, pass `trust_remote_code=True`.\"\n            )\n\n        # Get the tool's tool.py file.\n        tool_file = hf_hub_download(\n            repo_id,\n            \"tool.py\",\n            token=token,\n            repo_type=\"space\",\n            cache_dir=kwargs.get(\"cache_dir\"),\n            force_download=kwargs.get(\"force_download\"),\n            proxies=kwargs.get(\"proxies\"),\n            revision=kwargs.get(\"revision\"),\n            subfolder=kwargs.get(\"subfolder\"),\n            local_files_only=kwargs.get(\"local_files_only\"),\n        )\n\n        tool_code = Path(tool_file).read_text()","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/tools.py#L532-L568","documentation":"Tool.from_hub downloads and executes arbitrary Python code from a Hugging Face Hub repo. As a safety gate, it refuses to run unless the caller explicitly passes trust_remote_code=True.","triggerScenarios":"Calling load_tool(repo_id) or Tool.from_hub(repo_id) without trust_remote_code=True.","commonSituations":"Following older smolagents/transformers examples that predate the flag; CI scripts using load_tool without the flag after upgrading; forgetting the flag when switching from local tools to Hub tools.","solutions":["Pass trust_remote_code=True to load_tool / from_hub after reviewing the repo's tool.py code","Only do this for repos you or a trusted party control; inspect the code in the repo first","Prefer vendoring the tool code locally if trust is a concern"],"exampleFix":"# before\ntool = load_tool(\"huggingface-tools/text-to-image\")\n# after\ntool = load_tool(\"huggingface-tools/text-to-image\", trust_remote_code=True)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    tool = load_tool(repo_id)\nexcept ValueError as e:\n    if \"trust_remote_code\" in str(e):\n        # review the repo's tool.py, then:\n        tool = load_tool(repo_id, trust_remote_code=True)\n    else:\n        raise","preventionTips":["Always pass trust_remote_code=True explicitly for Hub tools after reviewing their source","Pin Hub tool revisions so reviewed code can't silently change","Never blanket-trust untrusted repos; the code executes in your process"],"tags":["smolagents","hub","trust-remote-code","security"],"backgroundTag":"trust-remote-code-required","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}