Learning resourcesReviewed · Pydantic

Pydantic AI Workspaces Guide

Pydantic AI’s Workspaces guide teaches Python agent developers to give agents access to files and commands, with the catch that local workspaces provide no isolation from the host. It explains the shared ctx.workspace interface, sandbox continuity, read-only access, file authority, durable execution and custom backends.

Researched 23 Nov 2026

In short.

Pydantic AI’s Workspaces guide is a practical reference for Python developers building agents that use files and commands, but developers must choose appropriate isolation and manage sandbox cleanup themselves. Its main value is explaining how the same tools can work across local directories, sandbox providers, later conversations and durable workflows. It documents failure handling, file-authority controls and backend conformance checks in detail. No examples or checks were executed, and the page supplies no pricing or performance measurements.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage is limited to the complete selected Workspaces documentation page at [https://pydantic.dev/docs/ai/core-concepts/workspace/index.md], captured on 2026-11-23. Its documentation-index and URL-parameter notices are included in the source. Linked pages, API references, provider documentation and repositories are excluded. No examples, installations, backend checks, sandbox operations or durable workflows were executed; runtime behavior, performance and provider-specific security remain unassessed.

The overview

identity

The resource is the Workspaces concept guide in Pydantic AI’s documentation at [https://pydantic.dev/docs/ai/core-concepts/workspace/index.md]. It describes the environment in which an agent reads and writes files or runs commands, accessed by tools through ctx.workspace. Its scope includes local workspaces, harness sandboxes, workspace references, access wrappers, durable execution and backend implementation.

assessment

This guide is useful when an agent needs a persistent project environment or when tool code should work across different environments. It connects basic command execution with the harder operational questions: how to resume work, reject a missing environment, restrict a reviewer and clean up after failure.

The explanations make several consequential distinctions clear: a starting directory does not contain an agent, file authority does not restrict tool permissions, and finishing an agent run does not delete its sandbox. The page offers implementation guidance, but does not establish measured reliability, isolation strength or production performance for any backend.

users

The main audience is Python developers building coding agents, file-processing assistants or agents that revisit a project over several conversations. Beginners need familiarity with Python functions, asynchronous calls and tool registration to follow the examples. Experienced developers get additional material on custom capability selection, backend contracts, symlink handling, workflow recovery and provider-specific limitations.

capabilities

The common workspace API supports command execution, text and byte reads and writes, directory listing, metadata inspection, existence checks, directory creation and removal. Commands return exit_code, stdout and stderr. A nonzero exit is a normal result; timeouts and unavailable environments use specific exceptions. Harness capabilities such as Coder, FileSystem and Shell supply tools that use this interface.

Workspace references support later runs and shared environments between agents. ReadOnlyWorkspace can give a reviewer file access while refusing changes and commands. The guide also covers workspace integration with Temporal, DBOS and Prefect, narrower capabilities under Azure Durable Task and Render Workflows, and a conformance suite for custom backends.

Using it

requirements

The examples use Python and Pydantic AI; harness examples additionally import pydantic_ai_harness. Running the illustrated agents requires access to the chosen model and, for remote environments, the relevant infrastructure. The page does not specify minimum Python versions, a complete dependency installation procedure or provider authentication setup.

LocalWorkspace requires an existing directory and a POSIX system such as macOS or Linux. WindowsWorkspace provides the Windows alternative using PowerShell. A filesystem-only backend can support file tools without a shell, but cannot execute commands. Temporal workers using a local workspace need the directory at the same absolute path on shared storage.

mechanism

Each run has one workspace. An explicit workspace= argument takes priority over the workspace reference in message history, which takes priority over the agent’s configured workspace capabilities. A WorkspaceRef contains a provider and an identifier. Model responses record this reference so serialized conversations can reconnect to the same environment.

A sandbox reference remains None until the environment is created. If a recorded sandbox has disappeared, access raises WorkspaceUnavailableError instead of silently replacing it with an empty environment. Passing workspace='new' deliberately starts again. Client-supplied histories have references stripped by sanitize_messages and UI adapters; the guide recommends storing trusted references on the server.

File authority controls how capabilities present workspace text to the model. The user and none settings lower the authority of externally authored files, and path_authority allows different levels within one workspace. These settings do not restrict reading, writing or execution. File content returned by a tool remains tool output, and lowering authority does not remove text already included in conversation history.

setup

The introductory configuration attaches LocalWorkspace('.') to an Agent and registers a tool that calls ctx.workspace.run with a command timeout. Tools can translate WorkspaceError into ModelRetry so the model can respond to the failure. The harness offers ready-made file and shell tools. For untrusted code, the guide recommends replacing the local capability with an isolated sandbox backend.

Environment variables should be passed selectively through env=. To resume work, retain message history or save result.workspace.ref. To end a sandbox’s lifetime, use its provider’s deletion mechanism. Failed runs require cleanup through an on_run_error hook because they return no result and do not invoke after_run. The page does not provide a complete provider-specific installation and deployment walkthrough.

example

The main walkthrough asks an agent to write fizzbuzz.py and run it. Its execute tool calls ctx.workspace.run(command, timeout=60), converts workspace exceptions into ModelRetry and returns either standard output or the command’s exit status and error output. A subsequent run asks for a test and supplies the earlier messages to retain the workspace.

Another example passes ReadOnlyWorkspace(ctx.workspace) to a reviewer agent that reads the same files. This illustrates sharing an environment while restricting the reviewer’s workspace operations. The success messages shown in the documentation are illustrative outputs; none of these examples was executed for this report.

Assessment & evidence

limitations

LocalWorkspace and WindowsWorkspace run with the host user’s access. Their working directories do not prevent absolute paths, parent-directory access or shell commands from reaching elsewhere. Symlink checks occur separately from file operations and do not defend against concurrent link changes. A wrapper that restricts file methods must also restrict run(), because commands can bypass those methods; ctx.workspace.backend provides another route around wrapper policies.

Durable execution has engine-specific constraints. DBOS serializes tool calls when a workspace is present. Temporal limits delegation to self and exposes only certain live events; it also applies activity timeouts. Workflow recovery rebuilds workspaces from references, so required capabilities and policies must be attached to the agent. Adding or removing workspace capabilities while runs are in flight can disrupt replay or recovery. Realtime sessions do not currently select workspaces.

Command deadlines exclude sandbox preparation, and timeout=None sets no command deadline. Local commands have a documented 10 MiB combined output limit. Background processes can outlive commands or runs and require cleanup. Workspace identifiers appear in run spans even with include_content=False; workflow-side file contents and environment arguments can enter durable history. Provider-specific isolation and termination behavior were not assessed.

reasoning

The shared interface should reduce changes to tool code when moving an agent between environments, because tools call ctx.workspace rather than a provider directly. That makes the guide particularly relevant to applications that need continuity or multiple backend choices. The tradeoff is operational responsibility: application developers still choose the isolation boundary, validate environment references, handle failures and manage lifetime. A consistent API does not establish identical security or performance across providers.

alternatives

The page describes several environment choices within the same interface. LocalWorkspace and WindowsWorkspace suit trusted work on the host. Harness options include E2B, Modal, Render, Sprites, Daytona, boxd, Kubernetes agent-sandbox, a local smolvm microVM and self-hosted OpenSandbox. Read-only wrappers support file inspection, while an agent without file tools suits tasks that need no file access.

The community package pydantic-ai-backend is described as supporting Kubernetes, Docker, Daytona, sandboxd and in-memory JSON documents. Developers can also implement a custom backend. The page provides no comparative pricing, benchmarks or independent security evaluation, and the linked provider and package documentation is outside this report’s scope.

evidence

The evidence is the complete captured Workspaces page at [https://pydantic.dev/docs/ai/core-concepts/workspace/index.md], captured on 2026-11-23 at 22:03:43.795 UTC. Its source SHA-256 is f281345e6421f18c774af753a7f720bae943f3afdbae89917d7ec80f1b4ee4c0. It contains explanatory prose, Python examples, platform constraints and backend conformance guidance.

These are documentation claims. No installation, command, model call, sandbox, durable workflow or conformance suite was run. The page’s example outputs do not establish measured success rates or performance. Linked API references, provider guides and repositories were not assessed.

Access & freshness

costs

The page gives no library pricing, model-token rates, sandbox tariffs, free allowances or total operating cost. Cost is unknown. Sandbox lifetime matters because environments can remain running after successful or failed runs until explicitly deleted or stopped by provider settings.

Durable runs create or attach their environment when the run starts, even without tool use. Ordinary runs create sandboxes lazily. Calling a method on result.workspace after a run that never used its sandbox, with ref=None, may create a new sandbox. Checking the reference and arranging cleanup are relevant to resource consumption.

rights

The page does not include a software licence, documentation reuse licence or explicit redistribution grant. Permissions to reuse its examples or redistribute the documentation are therefore unknown from this page. Licence and service terms for the named infrastructure providers and community packages are also not supplied.

freshness

The capture date identifies the available snapshot, not the page’s publication date or a software release. The page does not state a last-updated date or a complete release compatibility matrix. It says conformance-suite names are stable in 2.x, while minor releases can add or tighten rules. That statement does not identify the exact package version needed for every illustrated API, model identifier or provider integration.

actions

Before adopting the examples, establish whether the agent will handle trusted local work, inspect files without changes or execute untrusted code. Choose the environment accordingly, pass only necessary environment variables and define how workspace references will be stored, authorized and deleted. Obtain the relevant provider’s setup instructions, terms and prices before provisioning infrastructure.

For durable workflows, confirm engine-specific restrictions and keep workspace capabilities consistent during recovery and deployment. For a custom backend, run WorkspaceBackendSuite with fixtures for fresh creation, reattachment and destruction where applicable. Inspect skipped checks explicitly: the documented suite treats missing optional fixtures as unchecked behavior, and no conformance results are available here.

Evidence for this report

selected-page.txtselected · checked 2026-11-23