Pydantic Runs AI Agent Code Without a Virtual Machine, in the Rust-Based Monty Interpreter
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.
AI-processed from Habr AI; edited by Hamidun News
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.
- Nov 25, 2026An Agent Ran in Circles for Nearly an Hour, While Its Script Did the Job in 19 Seconds With No Tokens
- Nov 25, 2026Cloudflare Turns On Search for AI Agents on Any Site With One Toggle
- Nov 25, 2026Claude Can Now Install Artifacts as Desktop Apps on macOS and Windows
- Nov 25, 2026Agents Started Swearing: 14 of 102 Models Use Profanity in Drafts, and It Predicts Failure
Key Questions Answered
What are the key details on 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.
What are the key details on 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.
What are the key details on 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.
Test Frontier LLMs & Autonomous Agents in One Workspace
Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.
Waitlist: free vibecoding intensive + AI digest
Leave your email to reserve a spot in the free 2-day intensive and get the AI stories that matter.