huggingface/smolagents · error · InterpreterError

Deletion of {type(target).__name__} targets is not supported

Error message

Deletion of {type(target).__name__} targets is not supported

What it means

The interpreter only supports del on plain names (del x) and subscripts (del x[i]). Any other target — attribute deletion (del obj.attr), tuple targets (del (a, b)), or starred targets — is unsupported.

Source

Thrown at src/smolagents/local_python_executor.py:1413

        authorized_imports: List of authorized imports
    """
    for target in delete_node.targets:
        if isinstance(target, ast.Name):
            # Handle simple variable deletion (del x)
            if target.id in state:
                del state[target.id]
            else:
                raise InterpreterError(f"Cannot delete name '{target.id}': name is not defined")
        elif isinstance(target, ast.Subscript):
            # Handle index/key deletion (del x[y])
            obj = evaluate_ast(target.value, state, static_tools, custom_tools, authorized_imports)
            index = evaluate_ast(target.slice, state, static_tools, custom_tools, authorized_imports)
            try:
                del obj[index]
            except (TypeError, KeyError, IndexError) as e:
                raise InterpreterError(f"Cannot delete index/key: {str(e)}")
        else:
            raise InterpreterError(f"Deletion of {type(target).__name__} targets is not supported")


@safer_eval
def evaluate_ast(
    expression: ast.AST,
    state: dict[str, Any],
    static_tools: dict[str, Callable],
    custom_tools: dict[str, Callable],
    authorized_imports: list[str] = BASE_BUILTIN_MODULES,
):
    """
    Evaluate an abstract syntax tree using the content of the variables stored in a state and only evaluating a given
    set of functions.

    This function will recurse through the nodes of the tree provided.

    Args:
        expression (`ast.AST`):

View on GitHub (pinned to 30bb116109)

Solutions

  1. For attributes, set obj.attr = None instead of del obj.attr
  2. Delete tuple elements individually: del a; del b
  3. Restructure cleanup to reassignment rather than deletion

Example fix

# before
del obj.temp_attr
# after
obj.temp_attr = None
Defensive patterns

Strategy: fallback

Validate before calling

# in generated code: replace del obj.attr with reassignment
obj.attr = None

Try / catch

try:
    evaluate_python(code, ...)
except InterpreterError as e:
    if 'targets is not supported' in str(e):
        # rewrite deletion as reassignment and retry

Prevention

When it happens

Trigger: del obj.attr, del (a, b), or del a, in some AST shape not Name/Subscript.

Common situations: Agent code tries to remove an attribute from an object to clean up; uses tuple deletion; the sandbox being deliberately narrower than CPython's del semantics.

Related errors


AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28). Data as JSON: /api/errors/8eba5aa67634e5f3. Report an issue: GitHub.