In short.
This guide helps Python developers keep Pydantic AI coding work in E2B across runs and worker restarts, but applications must manage cleanup and repeated side effects during recovery. E2B supplies an isolated remote computer and persistent files, while Pydantic AI manages the agent loop. The page includes a log-analysis repair example with explicit output checks, explains workspace reattachment, and outlines Temporal recovery. Prices, licensing terms and measured reliability are not established, and no code was executed.
Researched and written by an AI model and checked by a second AI model. How it works
Covers the complete selected documentation page at [https://docs.e2b.dev/agents/pydantic-ai.md], including installation, the inline CLI example, pause and resume, Temporal recovery, ownership and lifetime guidance, and descriptions of the linked cookbook examples. Linked documentation, the documentation index and repository contents are outside scope. No licensing or pricing terms are supplied on the page, and linked terms were not assessed. No code was executed; compatibility, output, persistence, recovery, cleanup, performance and isolation were not independently verified.
The overview
Identity
Pydantic AI is an E2B documentation guide at [https://docs.e2b.dev/agents/pydantic-ai.md]. It explains the native E2B workspace provider in Pydantic AI's harness package. The resource is a guide to integrating existing components; it does not provide a separate application.
E2BSandbox supplies the execution environment. Pydantic AI capabilities such as Shell, FileSystem and Coder perform their commands and file operations inside that environment.
Assessment
The guide is useful when a coding agent needs to return to the same project files after another run, a pause or a worker restart. It explains ownership of the remote workspace, including settings, reattachment and deletion.
Its strongest practical feature is the example's independent acceptance check: application code runs the repaired CLI and verifies its output and unchanged input data. The main operational burden is that agent completion does not automatically delete the sandbox, and recovery can repeat interrupted operations. Actual behavior and reliability were not assessed.
Users
The guide suits Python developers building coding agents that need shell access, file editing and a workspace that survives between runs. Its Temporal material is relevant to developers operating background workers that may fail or restart.
Beginners will need familiarity with Python asynchronous code, API keys and command-line package installation. The page explains the integration through code rather than introducing those prerequisites.
Capabilities
The inline example gives an agent shell execution and file read, write and edit tools in a shared E2B workspace. It disables sandbox internet access, supplies an explicit environment and working directory, and limits model requests and execution time.
The page also describes pausing and resuming the same sandbox, continuing an agent conversation in another process, and recovering a Temporal worker using a saved workspace reference. Its linked cookbook descriptions cover checks for preserved files, the same sandbox ID and cleanup; those cookbook implementations were not inspected.
Using it
Requirements
The page specifies Python 3.11 or newer, pydantic-ai-harness[e2b]>=0.54.0 and pydantic-ai-slim[openai]>=2.54.0 for its OpenAI example. The process running the agent needs E2B_API_KEY and OPENAI_API_KEY. Other model providers require their corresponding Pydantic AI extra and model configuration.
Temporal recovery additionally requires the harness's temporal extra and Temporal workflow and worker configuration. A replacement process needs its own E2B_API_KEY because the saved workspace reference contains no credentials.
Mechanism
Pydantic AI manages the agent loop and workspace selection, while E2B supplies the remote computer and persistent filesystem. E2BSandboxBackend holds the working directory, environment and lifetime settings. When workspace=backend is supplied, the agent's E2BSandbox capability does not override those settings. Model calls happen on the host, and the page states that the sandbox does not inherit the host environment.
To continue later, save result.workspace.ref and result.all_messages(). Pass the reference as workspace and the messages as message_history on the next run, configuring the same working directory and environment. The first workspace operation reconnects and resumes a paused sandbox. The reference locates the workspace; the saved messages preserve the conversation.
Setup
Install the example dependencies with pip install "pydantic-ai-harness[e2b]>=0.54.0" "pydantic-ai-slim[openai]>=2.54.0", then set the two API keys in the host process. Create an E2BSandboxBackend and configure the agent with E2BSandbox, Shell and FileSystem. The example uses openai:gpt-4.1-mini.
For a retained workspace, obtain the SDK handle with await backend.get_sandbox() and pause it with await sandbox.pause(). For Temporal recovery, compose the agent with TemporalDurability, register it on a PydanticAIWorkflow and connect the client with PydanticAIPlugin. A replacement worker must use the same task queue, workflow, agent registration and saved reference.
Example
The example seeds log_stats.py and requests.jsonl with HTTP statuses 200, 500 and 503. The original CLI counts only status 500. The agent is asked to count every status from 500 through 599 while leaving requests.jsonl unchanged.
After the agent returns, the application runs the CLI itself and asserts a zero exit code, output of 2 and unchanged input data. The script specifies a 300-second sandbox lifetime, 20-second shell command timeouts and a 120-second outer deadline. Cleanup runs through a finally block. The documented success output is an expected result; no execution or successful repair was observed.
Assessment & evidence
Limitations
A killed or unavailable sandbox raises WorkspaceUnavailableError; the integration does not silently substitute an empty workspace. The page says native E2B sandboxes default to a 3,600-second lifetime and pause on timeout. The sandbox_timeout setting also applies on reattachment, while a command timeout separately bounds that command.
Temporal activities interrupted before completion is recorded may execute again, so their side effects must be repeatable. A worker stopping does not establish that its remote shell command stopped. Recovery does not guarantee exactly-once sandbox creation.
File-tool path restrictions do not constrain arbitrary shell commands. The page advises withholding unnecessary host-file transfer tools and API keys from the model. Isolation strength, recovery reliability and performance were not independently assessed.
Reasoning
Separating the workspace reference from message history makes two persistence needs explicit: retaining project files and retaining the conversation. Applications that need both must preserve both.
The example provides concrete acceptance conditions by checking actual CLI output and original input data. Its cleanup and recovery guidance also exposes responsibilities that persist after an agent returns. These documented design choices support practical evaluation, but the page supplies no measured reliability or performance results.
Alternatives
The page does not compare other agent frameworks, sandbox providers or local execution. Their relative costs and suitability are unknown from this evidence. Other model providers are mentioned, but no alternative provider is demonstrated.
Within the documented integration, workspace="new" creates an intentionally separate workspace, a saved reference supports returning to existing files, and Temporal adds recovery across worker restarts. These choices address different continuity needs.
Evidence
All findings rely on the complete captured page at [https://docs.e2b.dev/agents/pydantic-ai.md]. It contains installation instructions, an inline Python example, lifecycle guidance and descriptions of two cookbook examples.
The linked documentation and repository contents were not examined. Assertions about cookbook checks are descriptions made by this page. No code was executed, so successful repair, persistence, crash recovery and cleanup remain unverified.
Access & freshness
Costs
E2B rates, model API prices, pause or storage charges and total cost are unknown from this page. It says a sandbox can continue running and billing after an agent run until it is paused, deleted or its lifetime expires.
The example limits the agent to six requests and 30,000 input tokens and sets max_tokens to 1024. These are usage controls; the page supplies no monetary spending cap or measured cost for the task.
Rights
The supplied page includes no license or reuse terms for its documentation or sample code. Permission to redistribute those materials, and the licenses of the packages and linked cookbook projects, are not established by this evidence. Applicable rights must be checked at their original sources before reuse or redistribution.
Freshness
The page was captured on 26 November 2026 at 03:59:31.588 UTC. It supplies no publication or last-update date. Its package requirements are documented minimum versions, not evidence of the latest releases or compatibility with every newer version.
The cookbook links identify a fixed Git revision, but their contents and current availability were not assessed. Compatibility with a particular installed environment is unknown.
Actions
Start by checking the documented Python and package requirements, configuring host credentials and deciding whether each job should delete its workspace or retain it. When evaluating the sample yourself, verify the CLI exit code, expected count of 2 and unchanged requests.jsonl.
For retained work, save the reference and message history and preserve the working directory and environment settings. For recovery, verify the same sandbox ID and retained files, and make repeated side effects tolerable.
When finished, call await E2BSandbox().destroy(ref). The page says this deletes a paused sandbox by ID without resuming it. Preserve the reference and report cleanup errors so deletion can be retried. Establish actual provider costs and applicable reuse terms before committing to deployment or redistribution.
