Code Execution Beats Loading Hundreds of Tool Defs

A single code-execution tool — bash, Python, a REPL — often replaces dozens of specialized tools and avoids the context cost of registering a large tool set that the agent must reason over on every call.

What it is

Every tool registered in an agent's tool list occupies space in the context window through its name and description, and imposes a reasoning cost on the model that must evaluate each candidate tool before selecting one. A tool set that grows to 50 or 100 tools creates substantial overhead: the model attends to dozens of descriptions on every reasoning step, selection errors multiply as tools become harder to distinguish, and the total context budget consumed by tool definitions crowds out working content. Code execution tools — bash, a Python REPL, a JavaScript runtime — offer a different architecture: instead of registering a specialized tool for every operation, register one general-purpose executor and let the agent write the operation as code. Need to list files matching a pattern? Write a shell glob. Need to query a database? Write a SQL statement. Need to parse JSON? Write a jq expression or a Python one-liner. The tool definition cost is fixed at one description regardless of how many operations the agent needs to perform. The generality is bounded only by what the execution environment allows. This is not appropriate for all situations — code execution requires careful sandboxing, carries security implications, and is harder to audit than a predefined tool call — but when the alternative is a sprawling tool catalog that exceeds what a model can reliably reason over, code execution is the more reliable design.

When to reach for it

When NOT to

Exemplars

Related