Pydantic AI + Microsandbox

August 21, 2026 ยท View on GitHub

A minimal Pydantic AI agent with a run_command tool that executes commands in an isolated Microsandbox

The microVM is created for one agent run and stopped afterwards. It uses the python:3.13-slim image and has no network access.

Setup

Install dependencies with uv:

uv sync

Choose a Pydantic AI model and set the provider's API key as required by that provider. For example, after choosing an OpenAI model:

export OPENAI_API_KEY=...
uv run python agent.py "Calculate 6 factorial with Python." --model openai:gpt-5-mini

Microsandbox needs KVM enabled on Linux. The first execution downloads the microVM image; later runs use the local cache.

Commands

uv run python agent.py --help
uv run python -m py_compile agent.py