All studies

study 03 of 03

AI agent tool sandbox

A runtime for LLM tool calls: schema-validated dispatcher, permission gate, step counter, and timeout. The model is treated as an unreliable dependency.

The problem

An LLM with tool access can be prompted into calling tools it should not touch, looping indefinitely, or generating valid-looking JSON that crashes a handler at runtime. None of these are stopped by the model itself.

Constraints

  • Every tool call argument must be validated against a schema before execution.
  • Max steps per agent run: configurable ceiling, hard-enforced, not a prompt instruction.
  • Tools are scoped to a permission set per run. A read-only run cannot call write tools at all.
  • Total wall-clock timeout enforced at the runner level, independent of step count.

Architecture

Hover, tap, or tab into a box to read what it does.

start runprompt + historytool call or finaldispatch toolexecuteresultlog stepUser InputAgent RunnerLLMTool DispatcherTool PoolTrace Log
Hover, tap, or tab into a box to read what it does.

Trade-offs

Schema validation at dispatch, not at tool entry

instead of Validate inside each tool function

One missing schema check inside a tool means bad arguments reach execution. Validating at dispatch gives you a single enforcement point, and adding a tool cannot quietly skip it.

Hard step ceiling enforced by runner

instead of Instruction in system prompt

A model asked to stop after N steps may not. The runner increments a counter outside the model's awareness and halts the loop unconditionally.

Permission set per run, not per tool call

instead of Ask the model to choose permissions

The model cannot be a secure permission authority. Permissions are set by the caller at run creation and are immutable for the run's lifetime.

What I'd change

  • Add a sandboxed VM context for tool execution so a tool crash cannot bring down the runner process.
  • Add checkpointing so agent state is saved after each step. A timed-out run can resume instead of starting over.
  • Structured trace schema with OpenTelemetry spans for integration with existing observability stacks.