{"record":{"id":"91044f78bd64b0f9","repo":"huggingface/transformers","slug":"loading-this-model-requires-you-to-execute-custom","errorCode":null,"errorMessage":"Loading this model requires you to execute custom code contained in the model repository on your local machine. Please set the option `trust_remote_code=True` to permit loading of this model.","messagePattern":"Loading this model requires you to execute custom code contained in the model repository on your local machine\\. Please set the option `trust_remote_code=True` to permit loading of this model\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/dynamic_module_utils.py","lineNumber":703,"sourceCode":"\n    result = []\n    # Copy module file to the output folder.\n    object_file = sys.modules[obj.__module__].__file__\n    dest_file = Path(folder) / (Path(object_file).name)\n    shutil.copyfile(object_file, dest_file)\n    result.append(dest_file)\n\n    # Gather all relative imports recursively and make sure they are copied as well.\n    for needed_file in get_relative_import_files(object_file):\n        dest_file = Path(folder) / (Path(needed_file).name)\n        shutil.copyfile(needed_file, dest_file)\n        result.append(dest_file)\n\n    return result\n\n\ndef _raise_timeout_error(signum, frame):\n    raise ValueError(\n        \"Loading this model requires you to execute custom code contained in the model repository on your local \"\n        \"machine. Please set the option `trust_remote_code=True` to permit loading of this model.\"\n    )\n\n\nTIME_OUT_REMOTE_CODE = 15\n\n\ndef resolve_trust_remote_code(\n    trust_remote_code, model_name, has_local_code, has_remote_code, error_message=None, upstream_repo=None\n):\n    \"\"\"\n    Resolves the `trust_remote_code` argument. If there is remote code to be loaded, the user must opt-in to loading\n    it.\n\n    Args:\n        trust_remote_code (`bool` or `None`):\n            User-defined `trust_remote_code` value.","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/dynamic_module_utils.py#L685-L721","documentation":"When a model needs remote code and trust_remote_code is not set, transformers prompts interactively with a 15-second SIGALRM timeout. If you do not answer in time, the signal handler raises this ValueError — functionally 'permission denied by timeout'. It is also invoked directly when the CI sets the timeout to 0, guaranteeing non-interactive environments fail deterministically.","triggerScenarios":"Loading a remote-code model without trust_remote_code in a terminal where the [y/N] prompt is not answered within TIME_OUT_REMOTE_CODE (15 s), or in CI where the timeout is 0.","commonSituations":"Unattended scripts/cron jobs hitting the prompt; output buried under logs so the user never sees the question; notebooks where the prompt never displays.","solutions":["Pass trust_remote_code=True explicitly to from_pretrained (after reviewing the repo code at hf.co/<model>).","For batch jobs, make trust decisions at config level, not interactively.","If you did want the prompt, ensure stdin is a TTY and watch for it within 15 seconds."],"exampleFix":"# before\nAutoModel.from_pretrained(\"org/custom-model\")  # prompt times out after 15s\n\n# after\nAutoModel.from_pretrained(\"org/custom-model\", trust_remote_code=True)","handlingStrategy":"validation","validationCode":"# Non-interactive scripts: never rely on the 15s prompt.\nmodel = AutoModel.from_pretrained(repo_id, trust_remote_code=True)  # decide up front, after reviewing the repo","typeGuard":null,"tryCatchPattern":"try:\n    AutoModel.from_pretrained(repo_id)\nexcept ValueError as e:\n    if \"trust_remote_code=True\" in str(e):\n        raise SystemExit(f\"Non-interactive run: set trust_remote_code explicitly for {repo_id}\")\n    raise","preventionTips":["Make the trust decision a config flag, never an interactive prompt.","In CI, always pass trust_remote_code explicitly (True or False).","Review remote modeling code at hf.co/<repo>/tree/main before trusting it."],"tags":["trust-remote-code","security","interactive","timeout"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}