Learning resourcesReviewed · Pydantic

Pydantic AI Harness FileSystem documentation

This documentation guide helps Python developers give Pydantic AI agents file access, but its access controls do not provide security isolation. It explains workspace-scoped reading, editing and searching, access patterns, content hashes and events that can veto changes. Pydantic AI Harness is on 0.x releases, so minor upgrades can change its API.

Researched 24 Nov 2026

In short.

Pydantic AI Harness's FileSystem documentation is a guide for Python developers building agents that work with files, with a separate sandbox needed for security isolation. It documents eight default tools and two optional search tools, workspace requirements, path filtering, conflict detection and change events. Its most consequential caveats concern readable secrets, backend-dependent symlink protection, Shell access outside the file-tool boundary and evolving 0.x APIs. Runtime behavior, performance and security effectiveness were not tested.

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

Coverage is limited to the complete documentation page at [https://pydantic.dev/docs/ai/harness/filesystem/index.md], including usage examples, tool descriptions, pattern filtering, events, security caveats, configuration, durable-execution notes, deprecation notices and the on-page API reference. The documentation index, linked guides, repository source, release notes, package metadata and provider pages are excluded. License terms, exact release compatibility, runtime behavior, performance and security effectiveness remain unknown or unassessed. No code or commands were executed.

The overview

identity

The resource is the FileSystem documentation page for Pydantic AI Harness at [https://pydantic.dev/docs/ai/harness/filesystem/index.md]. It teaches a Python capability that adds file tools to a Pydantic AI agent, with usage examples, configuration details, security explanations and an API reference.

FileSystem operates through the run's workspace. That workspace can expose local files, sandbox files or custom storage. The page links to implementation source at [https://github.com/pydantic/pydantic-ai/tree/main/src/pydantic_ai_harness/pydantic_ai_harness/file_system/], but the linked implementation is outside the available evidence.

assessment

The guide is useful when an agent needs a consistent set of file operations and the application needs explicit rules about accessible paths. Its strongest material explains operational details that affect real integrations: stale edits, partial search results, approval events, remote workspaces and differences between search backends.

Its suitability depends on the intended security boundary. FileSystem can restrict its own tools, but LocalWorkspace does not isolate the agent from the host's operating-system authority. The documentation supports an architectural assessment; it does not establish measured reliability, speed or resistance to attacks.

users

The primary audience is Python developers building Pydantic AI agents for repository work, document inspection or controlled file changes. Beginners get a small Agent example; experienced developers get configuration semantics, typed events, custom-backend requirements and durable-execution caveats.

It is especially relevant to application developers who need to show proposed edits to a user, prevent stale writes or restrict agents to particular file types. It assumes an existing agent application rather than providing a standalone file-management assistant.

capabilities

The eight default tools read files, create or overwrite files, replace exact text, list directories, search file contents with regular expressions, find names with globs, create directories and inspect metadata. The optional list_files and grep tools add searches designed to use ripgrep inside the workspace.

Text reads include line numbers and, by default, a content hash. write_file and edit_file accept an optional expected_hash to reject changes based on stale content. Each edit target must match exactly once; replacement batches are checked in memory and written only when every replacement succeeds.

Supported images and PDFs up to 5 MB can be returned as files to compatible models. Other binary files receive descriptive output. Typed tool-call parts and structured events let applications recognize operations without depending on tool names or parsing the model-facing text.

Using it

requirements

An agent needs Pydantic AI, the pydantic_ai_harness package and an attached workspace. A run without a workspace fails at startup. LocalWorkspace supplies a local working directory; a sandbox capability or custom backend can supply another environment. Exact supported package versions, Python versions and a base installation command are not stated.

Fast searches require rg inside the workspace, including inside a remote sandbox. Installing it only on the agent host does not satisfy a remote workspace. Command-capable POSIX workspaces have fallbacks using git, grep and find; read-only or filesystem-only workspaces use Python file walks with different behavior.

Reliable symlink checks require the backend to resolve real paths. A custom backend needs SupportsFilesystem, with additional interfaces needed for command execution and real-path resolution. Returning images or PDFs also requires a model and provider that accept the corresponding file input.

mechanism

Relative paths start from the workspace's working directory. root_dir defaults to that directory and must contain it. Before file operations, FileSystem checks containment and access patterns, resolving symlinks when the backend supports it. Setting root_dir to / disables containment checks while leaving configured patterns active.

allowed_patterns limits accessible paths; denied_patterns overrides permission to read or write; read_only_patterns blocks writes while permitting reads. Patterns use fnmatch semantics, where * spans directory separators. Denied and read-only matching ignores case. Directory walkers check their starting directory against denied patterns, then filter returned entries against allowed and denied patterns.

Before a write, edit or directory creation, FileChangeRequestedEvent lets a listener cancel the operation. File writes and edits are checked again after the listener returns, including whether readable content changed during approval. Other events report completed activity. Changes run sequentially, while read tools can run in parallel.

setup

The documented starting configuration creates a workspace directory and adds LocalWorkspace('./workspace') and FileSystem() to an Agent's capabilities. With the default root_dir, the file tools operate within that workspace. To work inside a project subdirectory, configure the workspace's working directory rather than using FileSystem's deprecated cwd field.

Choose the exposed tools and access rules explicitly. For example, tools=['read_file', 'edit_file', 'list_files', 'grep'] registers that subset, while read_only=True removes change tools from the selection. A read-only workspace also narrows the available tools. Sensitive files need denied_patterns if the agent must not read them.

YAML or JSON agent specifications are supported, but Agent.from_file must receive custom_capability_types=[FileSystem], and the run still needs a workspace. The page also describes Temporal, DBOS, Prefect, Azure Durable Task and Render Workflows integration, with engine-specific restrictions on event delivery and listeners.

example

The page's introductory example asks an agent to read config.toml and report the package name. LocalWorkspace('./workspace') supplies the files, and FileSystem() supplies the reading tool. This illustrates the intended configuration; no execution result is provided here, and the example was not run.

The documented filtering example allows *.py and *.toml while denying **/node_modules/*. Because * spans directory separators, *.py also permits Python files in subdirectories. A separate example listens for FileChangeRequestedEvent and cancels proposed changes beneath migrations/, returning a reason to the model.

Assessment & evidence

limitations

Default protection for .git, .env files, keys, secrets and harness files prevents writes but still permits reads. It does not make secrets confidential. Shell commands ignore root_dir, and a symlink changed between the access check and actual use can evade the check. Filesystem-only backends without real-path support cannot detect symlink escapes.

Search results depend on the backend. POSIX fallbacks lack some ripgrep features and ignore-file behavior; Python walks do not apply ignore files or file_type filtering. Python regular expressions have no execution time limit. A heuristic rejects some nested repetitions, but other expensive patterns remain possible.

Default read output is limited to 2,000 lines and 50,000 characters; default listing and search limits are 1,000 results. Walks stop after 10,000 directories or 100,000 entries. Files over 64 MiB are described rather than returned as text, although backends without size reporting may read them before determining this. Search and read output should be interpreted with their continuation or truncation notices.

Change-event diffs can be truncated at 8,192 characters or replaced by file headers when diff generation would exceed other limits. An approval interface cannot assume every event contains the complete proposed change. On Azure Durable Task, listeners cannot perform I/O, so interactive external approval is not supported.

Missing-path behavior is described inconsistently: one passage says missing paths return a normal tool result without consuming the retry budget, while a later general error description includes missing files among ModelRetry cases. The exact distinction across tools is not consistently established by this page.

reasoning

The documented design centralizes file-access rules instead of requiring each tool to implement its own boundary. Content hashes address stale updates, while change-request events allow application decisions before changes reach storage. These mechanisms serve different purposes: a correct access policy does not resolve concurrent edits, and approval does not grant access to a denied path.

A practical inference is that configuration must cover every route by which an agent reaches files. Adding Shell can make FileSystem's root insufficient as an overall boundary. Another integration risk is documented directly: dedicated readers for Memory, RepoContext or spilled tool output can step aside when read_file is available, even if FileSystem's patterns then deny access to those files.

alternatives

The page supports architectural comparisons rather than comparisons with competing libraries. LocalWorkspace is the direct choice for files on the host; a sandbox workspace supplies a separate isolation boundary. A custom WorkspaceBackend can expose other storage while retaining FileSystem's filtering, hashes and events.

Shell with rg is discussed for large or generated trees, but Shell does not honor FileSystem's root_dir. Existing application file tools can emit the same event types for compatible subscribers, although the page does not establish that those tools implement equivalent access controls. No evidence supports ranking external filesystem libraries.

evidence

The evidence is the complete captured documentation page at [https://pydantic.dev/docs/ai/harness/filesystem/index.md], including its examples and on-page API reference. It was captured on 2026-11-24 at 01:45:21.621 UTC.

Behavioral statements are documentation claims, not observed execution results. Linked implementation files, release notes, provider documentation and other guides are outside the evidence. No runtime tests, security experiments, performance benchmarks or independent corroboration are available.

Access & freshness

costs

The page supplies no package pricing, model rates, sandbox charges or operating-cost estimates. Total cost is unknown and depends on the chosen model, workspace infrastructure and workload.

The documentation identifies choices that affect model context size: content hashes add tokens, reads have output limits, and searches cap their results. It provides no measurements showing token savings, latency or monetary impact.

rights

The page does not provide a software license, documentation license or redistribution terms. Permission to redistribute the documentation, package or example code is therefore unknown from this evidence. The linked source repository alone does not establish those rights.

freshness

The capture establishes the page's contents on 2026-11-24, but does not establish a publication date, exact package release or implementation commit. The page warns that Pydantic AI Harness remains on 0.x releases and may change APIs between minor releases.

Compatibility notices include protected_patterns being renamed to read_only_patterns, FileSystem.cwd being deprecated and ignored, and an event field named search being replaced by search_kind. These notices concern individual interfaces; the page does not identify FileSystem itself as deprecated.

actions

Before adopting the examples, establish compatible dependency versions and choose the workspace boundary. Use a sandbox where operating-system isolation is required. Configure the smallest useful tool set, keep root_dir limited to the intended files, and deny reads of secrets rather than relying on default read-only patterns.

For shared workspaces, retain content hashes and use expected_hash when changing previously read files. If users approve changes, handle cancellation, truncated diffs and content changes during approval. Confirm that the chosen execution engine supports the required listener behavior.

Validation should cover denied paths, symlinks on the actual backend, stale edits, search truncation and access to memory or spilled-output files. These are suggested adoption checks; their outcomes remain unknown because nothing was executed.

Evidence for this report

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