Vlad Sokolovskii

AI engineer building production software with AI

All writing

Telegram post

Why AI agents need sandboxes

  • #ai
  • #dev_tool

Sandboxes are isolated cloud environments where you can run code generated by an AI agent.

There are currently two main approaches:

  1. Give the agent access to MCP, write custom tools, and describe how those tools should be orchestrated in a skill or system prompt.
  2. Give the agent access to the CLI or REST API of the service you want to integrate with, then ask it to perform an action by generating code.

Most companies are still trying to make the first approach work without seriously considering the alternative. It is a good fit when you have clear user stories that can be covered by a couple of high-level tools. I wrote about building an MCP server properly here. But when you have only a vague idea of the use cases your users will invent, giving the agent freedom to decide how and in what order to call tools can be a strong solution.

The problem is where to execute that code. You certainly do not want to run arbitrary generated code directly on your own infrastructure. You need scaling, CPU and memory limits, and a way to hide every file the agent should not access. It quickly becomes a security and DevOps headache.

Products such as E2B, Daytona, Modal, Runloop, Vercel Sandbox, and Cloudflare Sandbox solve this problem.

Here is a simple example:

from e2b_code_interpreter import Sandbox

agent_code = "x = 21 * 2\nx"  # returned by your agent; it could contain anything

with Sandbox.create() as sandbox:
    result = sandbox.run_code(agent_code)
    print(result.text)

These environments are usually ephemeral: once a session ends, unnecessary artifacts do not remain on your primary infrastructure. A sandbox does not remove the need to configure network access, secrets, resource limits, and approval rules for dangerous actions.

This paradigm is still not especially popular among people building custom agents, although many coding agents already combine isolation with approvals. Codex, for example, has dedicated sandboxing and approval policies.

As part of my day job, your humble servant built the E2B integration for LangChain — langchain-e2b — so I can flex my open-source contributions in front of impeccably polished recruiters.

The AI engineering stack is already broad and complex. You have to keep up with trends constantly, but the market rewards it. Today’s market for AI specialists feels like cloud engineering in 2015, when putting AWS in your profile was enough to attract a stream of recruiters. If you do not believe me, add a few keywords such as RAG, agents, and OpenAI API to LinkedIn. At least it will blow some dust off that godforsaken profile.

The sun is firing photons into my epidermis, and I can feel my skin developing a delicious crust like rotisserie chicken. Leave some fire reactions so it gets even hotter 🔥

AI digest

Weekly newsletter

New articles, tools, and thoughts on where AI development is going. Only things I have tested myself.

AI DIGEST

New articles, tools, and thoughts on where AI development is going. Only things I have tested myself.

You can unsubscribe at any time