Pydantic AI
Run Pydantic AI's Shell and FileSystem capabilities in an E2B sandbox. The native E2BSandbox workspace keeps its files across runs, pauses and worker restarts.
- Pydantic
- Built into pydantic-ai-harness
- pydantic-ai-harness[e2b]
- Python
Get started
Paste the prompt into your coding agent, or follow the steps yourself.
Paste this into your coding agent
Add E2B sandboxes to this Pydantic AI project.
- 1.Install pydantic-ai-harness with the e2b extra ("pydantic-ai-harness[e2b]") using the project's package manager. It needs Python 3.11 or newer.
- 2.The sandbox needs the E2B_API_KEY environment variable. If it isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode it.
- 3.Follow the Pydantic AI guide at https://docs.e2b.dev/agents/pydantic-ai. Create an E2BSandboxBackend, give my agent the E2BSandbox, Shell and FileSystem capabilities, pass the backend as workspace=, and destroy the sandbox in a finally block.
- 4.Run the agent once and show me the output that came from the sandbox.
Or set it up yourself
1. Install the E2B integration
2. Set your API keys
3. Give the agent an E2B workspace
4. Run it and clean up
What runs in the sandbox
Commands and file edits run in an isolated sandbox; the agent loop and model calls stay on your machine.
- Shell commands and file edits from the Shell, FileSystem and Coder capabilities.
- Save result.workspace.ref and pass it back as workspace= to reconnect. A paused sandbox resumes with its files.
- Sandboxes default to a 3,600-second lifetime and pause on timeout. Pydantic AI never deletes them; call destroy(ref).
- API keys stay in the process running the agent. The sandbox doesn't inherit your environment.
More agent frameworks
Other frameworks that run their tools on E2B.
