---
id: 18211
lang: en
title: "Pydantic Runs AI Agent Code Without a Virtual Machine, in the Rust-Based Monty Interpreter"
published_at: "2026-11-25 16:30:28"
source_name: "Habr AI"
source_url: "https://habr.com/ru/companies/spring_aio/articles/1112322/?utm_campaign=1112322&utm_source=habrahabr&utm_medium=rss"
canonical_url: "https://news.hamidun.com/en/news/18211"
categories: ["ethics", "autonomous"]
publisher: "AI News by Jemal Hamidun (news.hamidun.com)"
---

# Pydantic Runs AI Agent Code Without a Virtual Machine, in the Rust-Based Monty Interpreter

> **Краткая суть (BLUF):** Code written by an AI agent has to run in an isolated sandbox, so that a mistake doesn't wipe files or leak keys. The usual approach is to spin up a full virtual machine, but Pydantic's Agent Sandboxes uses Monty, a lightweight interpreter written in Rust. It understands a restricted subset of Python and sees only the functions it is allowed to call. For a task like "filter customers and total the amount," that is enough. A heavy VM is needed only when the agent installs packages and runs processes.  • E2B, Daytona, Modal: pause, snapshots, and startup in fractions of a second • Docker Sandboxes injects keys through a proxy, so the agent never sees them • Fly.io Sprites and Blaxel put idle environments to sleep to save money

When an AI agent writes code, that code has to run somewhere. If it runs on a developer's laptop or on a production server, one mistake or a successful prompt injection can wipe files or leak keys. That's why the code runs in a "sandbox," an isolated environment with limited permissions. Most often the sandbox is a full virtual machine (VM), but Pydantic chose a different path in its new Agent Sandboxes service. It runs the agent's code in Monty, a lightweight interpreter written in Rust. Monty understands only a restricted subset of Python and sees only the functions the application has allowed. If the agent needs to load customer records, filter them, and total the amount, a separate machine isn't required. Let's look at what has already become standard for sandboxes and where the industry is still looking for solutions.

## Isolation and state: what is already standard

Providers such as E2B, Daytona, Modal, Vercel Sandbox, and Cloudflare Sandboxes offer similar APIs: create an environment, run a command, transfer files, and manage the lifecycle. For isolation they use Firecracker, which launches lightweight virtual machines with their own kernel, or gVisor, which intercepts system calls in user space. Ordinary containers share the kernel with the host, so their attack surface is wider.

Local agents are built differently. Claude Code restricts file and network access using operating system tools, and Codex relies on mechanisms specific to its platform. For clusters there is the Kubernetes Agent Sandbox project, which provides stateful sandboxes, templates, and pools of pre-prepared environments.

The second essential requirement is state preservation. If an agent works for longer than a single run, recreating the environment after every pause is too expensive: dependencies have to be installed again and processes restarted. E2B can pause and resume sandboxes, Daytona supports snapshots, and Modal provides persistent storage and filesystem snapshots. A memory snapshot also preserves running processes. From a snapshot you can create several branches: different agents start from the same point, try different solutions, and the result of each branch is checked before merging.

## The reverse trend: an agent doesn't always need a computer

Many agents only need a short program that calls several tools and processes intermediate results. The model generates Python code, and Monty executes the whole program in a single run, without contacting the model again for each operation. In Pydantic AI this is implemented through CodeMode, using a single run_code tool.

The price of simplicity is tight constraints. Monty cannot install packages or run OS commands. Code receives only explicitly permitted functions and runs within set resource limits. In return, far less infrastructure is needed. Agent Sandboxes still supports long-lived sessions, snapshots, and branching, but only the Python state is preserved, not the entire operating system.

## Cost, security, and observability

For most of the time an agent waits for a response from a model, an external service, or a person, and barely loads the CPU. Keeping thousands of idle sandboxes running is expensive, so Fly.io Sprites and Blaxel put environments to sleep when idle and wake them on demand. E2B and Daytona claim startup in milliseconds or fractions of a second under certain conditions, for example when using pools of ready environments.

Isolation alone does not protect against secret leaks. Even inside a micro-VM, an agent can send an extra API request or pass data over an allowed connection. In Docker Sandboxes, keys are injected by a proxy on the host side: the service is accessible, but the secret is not visible to the agent. Network policies determine where the agent can go, while authorization policies determine what it can do: change a repository, read a customer record, or execute a transaction.

Telemetry helps in understanding what the agent did inside the sandbox. Agent Sandboxes integrates with Logfire and links events to the agent's traces. Daytona collects logs, metrics, and traces through OpenTelemetry.

## What to do about it

It's important to decide where the agent loop itself lives. It can run outside and send only tool calls to the sandbox: in that case the agent process is easy to replace and can connect to the same working environment. It can run entirely inside the sandbox, which simplifies file access, but then the agent's secrets and state fall within the same isolation boundary. A third option is multiple environments: a restricted interpreter for the model's programs and a separate micro-VM for shell commands and repository operations.

The practical takeaway: isolation, snapshots, and observability will soon be available from any provider, so the choice should be driven by the task. For short computations a lightweight interpreter is enough, while a full VM is needed when the agent installs packages and runs processes. This is an overview piece: it contains no independent measurements of speed or cost, only vendor claims.

---
- **Первоисточник:** [Habr AI](https://habr.com/ru/companies/spring_aio/articles/1112322/?utm_campaign=1112322&utm_source=habrahabr&utm_medium=rss)
- **Каноническая ссылка:** https://news.hamidun.com/en/news/18211
- **Экосистема автора:** [Бесплатный интенсив по вайбкодингу — предзапись в Нике](https://t.me/vibecodeguidebot?start=agent_intensive_news_md) · [Nomad AI](https://nomadnet.ai) · [Telegram @jemal_hamidun](https://t.me/jemal_hamidun)
