← AI Techniques Radar
Inference efficiency

AST-guided whitelisted interpreter for LLM-generated code

Use an interpreter that parses LLM-produced Python into an abstract syntax tree (AST) and executes nodes only if they are explicitly authorized. The system blocks or skips operations not present in allowlists (e.g., specific imports, built-in functions, and tool calls), and halts when it encounters disallowed operations or safety limits.

Discovered 2026-11-10 · Sources checked 2026-11-10

This summary was generated with AI assistance.

Why it matters

Directly executing arbitrary LLM code is unsafe. AST-based execution with explicit allowlists constrains the action space to intended operations, while still letting the agent use code for multi-step tool calling and variable reuse.

What changed

Instead of using a fully functional interpreter with forbidden actions, the approach builds a restricted interpreter from the ground up: it walks the AST and executes only explicitly authorized operations, adding execution caps (operation count) and output truncation (print line limit).

Where it helps

  • Tool-using code agents that need safe execution
  • Agents that must call external tools via structured code
  • Constrained environments requiring allowlisted language features
  • Systems needing readable, inspectable execution traces

Evidence & reproduction

Reproduction not evaluated. A linked paper or repository does not establish independent reproduction.

Limitations & open questions

The method depends on maintaining correct allowlists (e.g., authorized imports/functions/tools). Over-restricting can prevent needed actions, and under-restricting can allow unsafe behavior.

Sources