chapter eight

8 Empowering agents with code execution

 

This chapter covers

  • Understanding the limitations of predefined tool approaches and the benefits of code execution
  • Connecting code-execution environments to agents
  • Porting tools to sandboxes for efficient execution
  • Providing complete workspaces with filesystems and the CLI
  • Using agent skills for hierarchical tool management

So far, we’ve built agents that register tools and have the large language model (LLM) select and call appropriate tools. This approach is predictable and easy to control, but it reveals clear limitations when applied to complex real-world problems. Let’s explore a new approach. Instead of creating individual functions as tools, we’ll provide an execution environment in which the LLM can write and run code directly. This is what it means to give an agent a computer.

As shown in figure 8.1, we’re ready to enhance agents with context-engineering strategies. We’ll focus on agent workspace, giving agents the same working environment that human developers use.

Figure 8.1 Chapter 8: providing complete workspaces

8.1 Giving agents a computer

8.1.1 Limitations of the predefined-tool approach

8.1.2 What code execution brings

8.1.3 The effectiveness of code-based actions

8.2 Connecting code environments

8.2.1 Why sandboxes are necessary

8.2.2 Introduction to E2B

8.2.3 Connecting the sandbox to the agent

8.2.4 Testing the code-execution agent

8.3 Porting tools to sandboxes

8.3.1 The need for tool portability

8.3.2 Extending FunctionTool

8.3.3 Implementing the Wikipedia revision tool

8.3.4 Handling sandbox tools in the Agent

8.3.5 Practical testing

8.4 Workspace: Using filesystems and the CLI

8.4.1 The workspace concept