{"record":{"id":"679e31360b4ee463","repo":"huggingface/smolagents","slug":"invoking-a-builtin-function-that-has-not-been-expl","errorCode":null,"errorMessage":"Invoking a builtin function that has not been explicitly added as a tool is not allowed ({func_name}).","messagePattern":"Invoking a builtin function that has not been explicitly added as a tool is not allowed \\((.+?)\\)\\.","errorType":"exception","errorClass":"InterpreterError","httpStatus":null,"severity":"error","filePath":"src/smolagents/local_python_executor.py","lineNumber":907,"sourceCode":"                return super(state[\"__class__\"], state[\"self\"])\n            else:\n                raise InterpreterError(\"super() needs at least one argument\")\n        cls = args[0]\n        if not isinstance(cls, type):\n            raise InterpreterError(\"super() argument 1 must be type\")\n        if len(args) == 1:\n            return super(cls)\n        elif len(args) == 2:\n            instance = args[1]\n            return super(cls, instance)\n        else:\n            raise InterpreterError(\"super() takes at most 2 arguments\")\n    elif func_name == \"print\":\n        state[\"_print_outputs\"] += \" \".join(map(str, args)) + \"\\n\"\n        return None\n    else:  # Assume it's a callable object\n        if (inspect.getmodule(func) == builtins) and inspect.isbuiltin(func) and (func not in static_tools.values()):\n            raise InterpreterError(\n                f\"Invoking a builtin function that has not been explicitly added as a tool is not allowed ({func_name}).\"\n            )\n        if (\n            hasattr(func, \"__name__\")\n            and func.__name__.startswith(\"__\")\n            and func.__name__.endswith(\"__\")\n            and (func.__name__ not in static_tools)\n            and (func.__name__ not in ALLOWED_DUNDER_METHODS)\n        ):\n            raise InterpreterError(f\"Forbidden call to dunder function: {func.__name__}\")\n        return func(*args, **kwargs)\n\n\ndef evaluate_subscript(\n    subscript: ast.Subscript,\n    state: dict[str, Any],\n    static_tools: dict[str, Callable],\n    custom_tools: dict[str, Callable],","sourceCodeStart":889,"sourceCodeEnd":925,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L889-L925","documentation":"The sandboxed executor only allows calling builtin functions (like len, sum, open, exec) if they were explicitly registered as tools in static_tools. This blocks agent code from escaping the sandbox via arbitrary builtins.","triggerScenarios":"Calling any builtin (e.g. open('f'), exec(s), eval(s), input(), help(), compile()) that is not in the agent's tools and not in the interpreter's small allowed set.","commonSituations":"Agent-generated code tries to open files, read stdin, or exec dynamic strings; using a builtin shadowed by an import; relying on builtins available in normal Python but not whitelisted by smolagents.","solutions":["Add the needed function to static_tools (or the agent's tools) when constructing the executor/agent, e.g. add smolagents's safe functions or your own wrapper","Replace the builtin with an allowed tool (e.g. read files via a provided file-reading tool instead of open())","Restructure the code to avoid the builtin entirely (use math instead of sum-of-floats tricks, string methods instead of format builtins, etc.)"],"exampleFix":"# before\ncontent = open('data.txt').read()  # blocked\n# after\n# provide a tool:\n# agent = ToolCallingAgent(tools=[ReadFileTool()], ...)\ncontent = read_file('data.txt')","handlingStrategy":"fallback","validationCode":"# before running agent code, register the builtins you actually need\nstatic_tools = base_python_tools.copy()\nstatic_tools['len'] = len  # example: explicitly allow","typeGuard":null,"tryCatchPattern":"try:\n    evaluate_python(code, static_tools=static_tools, ...)\nexcept InterpreterError as e:\n    if 'not been explicitly added as a tool' in str(e):\n        # parse builtin name, add to static_tools or rewrite code, retry","preventionTips":["Whitelist required builtins in static_tools up front","Replace builtins like open/exec/input with dedicated tools","Expect this error on sandbox-escape attempts and treat as a security signal"],"tags":["python-executor","sandbox","builtin","security","smolagents"],"backgroundTag":"sandboxed-builtin-not-allowed","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}