{"record":{"id":"158cec7bfbafcd07","repo":"huggingface/smolagents","slug":"expression-class-name-is-not-supported","errorCode":null,"errorMessage":"{expression.__class__.__name__} is not supported.","messagePattern":"(.+?) is not supported\\.","errorType":"exception","errorClass":"InterpreterError","httpStatus":null,"severity":"error","filePath":"src/smolagents/local_python_executor.py","lineNumber":1569,"sourceCode":"    elif isinstance(expression, ast.Try):\n        return evaluate_try(expression, *common_params)\n    elif isinstance(expression, ast.Raise):\n        return evaluate_raise(expression, *common_params)\n    elif isinstance(expression, ast.Assert):\n        return evaluate_assert(expression, *common_params)\n    elif isinstance(expression, ast.With):\n        return evaluate_with(expression, *common_params)\n    elif isinstance(expression, ast.Set):\n        return set((evaluate_ast(elt, *common_params) for elt in expression.elts))\n    elif isinstance(expression, ast.Return):\n        raise ReturnException(evaluate_ast(expression.value, *common_params) if expression.value else None)\n    elif isinstance(expression, ast.Pass):\n        return None\n    elif isinstance(expression, ast.Delete):\n        return evaluate_delete(expression, *common_params)\n    else:\n        # For now we refuse anything else. Let's add things as we need them.\n        raise InterpreterError(f\"{expression.__class__.__name__} is not supported.\")\n\n\nclass FinalAnswerException(BaseException):\n    \"\"\"Exception raised when final_answer is called.\n\n    Inherits from BaseException instead of Exception to prevent being caught\n    by generic `except Exception` clauses in agent-generated code.\n    \"\"\"\n\n    def __init__(self, value):\n        self.value = value\n\n\ndef evaluate_python_code(\n    code: str,\n    static_tools: dict[str, Callable] | None = None,\n    custom_tools: dict[str, Callable] | None = None,\n    state: dict[str, Any] | None = None,","sourceCodeStart":1551,"sourceCodeEnd":1587,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L1551-L1587","documentation":"smolagents' local Python executor only implements a whitelist of AST node types; any statement or expression outside that whitelist (e.g. global, nonlocal, async constructs, match statements, walrus in unsupported positions) hits the fallback branch and raises InterpreterError with the node class name. This is a deliberate safety limitation of the sandboxed interpreter used to run agent code actions. The error names the exact unsupported AST class to tell you what construct to rewrite.","triggerScenarios":"Calling evaluate_python_code or agent.run with code containing constructs like `global x`, `async def`, `await`, `match ... case`, `assert`, or any node not handled in evaluate_ast's isinstance chain.","commonSituations":"LLM-generated code actions using modern Python syntax (match statements, async/await) or side-effectful statements (global/nonlocal) inside a CodeAgent with local_python_executor; upgrading Python versions that introduce new AST nodes.","solutions":["Rewrite the code action to avoid the unsupported construct named in the message (e.g. replace `match/case` with if/elif, avoid `global`)","Check the full list of supported node types in local_python_executor.py evaluate_ast and constrain your prompt/tool descriptions accordingly","Use E2BSandboxExecutor or DockerExecutor instead of the local interpreter for full Python support","If a common construct is genuinely needed, open a feature request or subclass the interpreter"],"exampleFix":"# before\ncode = \"match x:\n    case 1: y = 'a'\n    case _: y = 'b'\"\nevaluate_python_code(code, state=state)\n\n# after\ncode = \"y = 'a' if x == 1 else 'b'\"\nevaluate_python_code(code, state=state)","handlingStrategy":"validation","validationCode":"import ast\nSUPPORTED = {ast.Assign, ast.AugAssign, ast.For, ast.While, ast.If, ast.FunctionDef, ast.Return, ast.ClassDef, ast.Call, ast.BinOp, ...}\nunsupported = [n.__class__.__name__ for n in ast.walk(ast.parse(code)) if not isinstance(n, (ast.expr_context, ast.operator, ast.boolop, ast.unaryop, ast.cmpop)) and not any(issubclass(n.__class__, s) for s in SUPPORTED)]\nif unsupported:\n    code = rewrite_or_reject(code, unsupported)","typeGuard":"def uses_only_supported_nodes(code: str) -> bool:\n    try:\n        tree = ast.parse(code)\n    except SyntaxError:\n        return False\n    return all(is_supported(n) for n in ast.walk(tree))","tryCatchPattern":"from smolagents.local_python_executor import InterpreterError\ntry:\n    executor(code_action)\nexcept InterpreterError as e:\n    if 'is not supported' in str(e):\n        code_action = simplify_constructs(code_action)  # e.g. match -> if/elif","preventionTips":["Instruct the LLM in the system prompt to use plain Python (no match, async, global) for code actions","Prefer if/elif over match/case and avoid global/nonlocal in generated code","Use E2B or Docker executors when full language support is required"],"tags":["smolagents","python-executor","ast","unsupported-syntax"],"backgroundTag":"unsupported-language-construct","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}