In short.
This guide helps Python developers add shell execution to Pydantic AI agents, but containing untrusted commands requires an isolated workspace. It documents tools for short commands and background jobs, configurable command restrictions, environment filtering, secret masking and output limits. Important limitations include incomplete protection for secrets, platform differences and changing APIs during 0.x releases. No examples were executed; runtime reliability, costs and licensing are not established.
Researched and written by an AI model and checked by a second AI model. How it works
Covers the complete page at [https://pydantic.dev/docs/ai/harness/shell/index.md], including its examples, API reference, security warnings, platform differences and version-policy notice. The captured source revision is sha256:fd18c9c8bcfc0dce9b08f8f7db0f4f615a042853fd094098c55cec32d8d6e5b1. Linked pages and repository files are excluded. No code was executed; runtime behavior, compatibility, containment effectiveness, costs and licensing remain unassessed or unknown as stated.
The overview
Identity
The resource is the Shell documentation and API reference for Pydantic AI Harness. Shell is a Python capability attached to a Pydantic AI Agent so the model can run commands in an associated workspace. The page combines integration examples, configuration defaults, lifecycle explanations and operational limitations.
The original page is [https://pydantic.dev/docs/ai/harness/shell/index.md]. It links to implementation code at [https://github.com/pydantic/pydantic-ai/tree/main/src/pydantic_ai_harness/pydantic_ai_harness/shell/], but that code is outside the available evidence.
Assessment
The guide is useful for integrating agents that build software, inspect repositories, run linters or tests, and manage development servers. Its practical strength is explaining subprocess details that otherwise require application code: timeouts, output truncation, process tracking and termination.
Adoption requires care about where commands execute. The documentation explicitly describes command restrictions as accident prevention rather than a security boundary. The examples and explanations support planning an integration, but successful execution, containment and reliability were not assessed.
Users
The main audience is Python developers building Pydantic AI agents that need command-line tools. Beginners get concrete examples of attaching a workspace and limiting command names; experienced developers get details about process groups, environment inheritance, persistent jobs and durable execution.
The material assumes familiarity with Python imports, agent configuration and shell commands. It is less suitable for someone seeking a ready-made terminal assistant, because using the documented capability requires application integration.
Capabilities
By default, Shell exposes run_command for commands that return output and an exit status, start_command for background jobs, check_command for their status and accumulated output, and stop_command for termination. Background jobs can continue across agent runs in the same workspace.
An optional shell tool replaces those four tools. It can wait in foreground mode or return immediately in background mode, providing a process ID and paths to output and status files. Foreground waiting is capped at 270 seconds, after which the command may still be running.
Configuration covers command names, shell operators, interactive commands, environment variables, returned output, background logs and optional per-file size limits. The page also documents YAML/JSON agent specifications and integration with durable execution engines.
Using it
Requirements
The examples use pydantic_ai and pydantic_ai_harness with an Agent and a workspace. A missing workspace causes the run to fail at startup. A read-only workspace provides no Shell tools, and required executables must exist in the workspace environment.
Background tools and the persistent shell tool require mv and base64 on the workspace PATH. WindowsWorkspace uses PowerShell for those tools and does not offer run_command. The per-file size limit requires a POSIX workspace.
The page names Temporal, DBOS, Prefect, Azure Durable Task and Render Workflows integrations, with capabilities varying by engine. Their linked compatibility details are outside this page. Minimum Python and package versions are not specified.
Mechanism
Before starting a process, Shell checks the command name, configured operators and interactive-command restrictions. A nonempty allowed_commands list selects allowlist mode; it cannot be combined with a nonempty denied_commands list. Without an allowlist, destructive command names such as rm and dd are blocked by default. Operator restrictions default to empty, and interactive commands are blocked by default.
Validation checks the first command token. Allowed programs such as Python, Git or Make can start other processes, so allowing them does not constrain everything they can do. Rejected commands and other recoverable failures return ModelRetry so the model can try another approach. Infrastructure failures can abort the run.
The default command timeout is 30 seconds and returned output is capped at 50,000 characters, retaining the end. Background jobs log output in the workspace. On workspaces with process-group support, stopping a job sends SIGTERM to the group, then SIGKILL after a grace period.
Setup
Import Agent from pydantic_ai, LocalWorkspace from pydantic_ai.capabilities and Shell from pydantic_ai_harness. Attach the workspace and Shell through the agent's capabilities parameter. Set the starting directory on LocalWorkspace; the deprecated Shell.cwd setting is ignored.
Configure only the commands and environment variables the task needs. LocalWorkspace normally passes PATH, HOME, LANG, LC_ALL and LC_CTYPE, plus its explicitly configured environment. Shell.env adds variables, while denied_env_patterns filters only Shell.env and does not filter variables supplied by the workspace.
For configuration files, declare Shell under capabilities, pass custom_capability_types=[Shell] to Agent.from_file and attach a workspace separately. The page does not provide installation commands or dependency pins.
Example
The repository-inspection example combines LocalWorkspace('./workspace') with Shell(allowed_commands=['ls', 'cat', 'rg']). It asks the agent to list Python files and summarize the largest one. This illustrates how to expose familiar inspection commands within a designated working directory.
Another example allows npm and curl, then asks the agent to start a development server and request its health endpoint. The page supplies the intended task, but no observed server startup, health response or repository summary. Neither example was executed.
Assessment & evidence
Limitations
Command filters and secret masking do not isolate execution. With LocalWorkspace, commands can still reach host files and the process environment. secret_env masks exact secret values in returned results and failure messages, but transformed values, files, logs and persistent-shell events can expose them. The supplied credential-name patterns do not cover every kind of secret.
max_file_bytes limits individual regular files, not total disk usage. It leaves partial files, permits many smaller files and cannot be combined with persist_cwd=True or tools=['shell']. Background and persistent-shell logs default to a 100,000,000-byte limit, checked once per second; exceeding it clears earlier output without stopping the command.
Cleanup has platform limits. Without setsid, stopping a background job may signal only its wrapper, leaving commands or children running. Commands receive end-of-file on stdin, with no tool for later input. Persistent-shell logs require manual cleanup, and a finished event can mean the tool stopped waiting while the command continues.
Reasoning
The main engineering benefit is combining command lifecycle handling with controls an application can configure. Timeouts, bounded returned output, retryable errors and job identifiers address different failure modes; none establishes containment by itself.
The workspace therefore determines the real exposure. A narrow command list can reduce accidents, while an isolated workspace limits what those commands can access. Separately configuring output, log and file limits matters because limiting the text shown to the model does not limit everything written to disk.
Alternatives
The page offers several approaches within Shell. Use run_command for a result returned within a timeout, the background tools for jobs managed by ID, or the persistent shell tool for processes tracked through log and status files. Adding BackgroundTools around run_command delivers completion output as a follow-up message instead of requiring polling.
For execution location, it describes LocalWorkspace and isolated workspaces such as a Modal sandbox or container. The linked sandbox documentation is outside scope. No comparative evidence supports ranking Shell against other agent libraries or shell-execution tools.
Evidence
The evidence is the complete Shell documentation page at [https://pydantic.dev/docs/ai/harness/shell/index.md], captured at 2026-11-24T02:13:09.471Z. It includes examples, defaults, operational caveats and the Shell API reference.
These are documented behaviors rather than observed results. No commands, examples, compatibility checks, performance benchmarks or security tests were executed. Linked documentation and repository implementation files were not assessed.
Access & freshness
Costs
The page does not state package pricing, model charges, sandbox rates or total operating costs. These remain unknown; the documentation does not establish that an integration is free.
An application needs its chosen model and an execution environment, whether local or hosted. Their resource use and charges depend on the deployment. No cost measurements or estimates are provided.
Rights
The page links to source code but includes no licence text or explicit permissions for modifying or redistributing the package, documentation or examples. Those rights are unknown from this evidence. A repository link alone does not establish a licence grant.
Freshness
The captured page says Pydantic AI Harness is on 0.x releases and warns that minor releases may change the API, with deprecation warnings and migration guidance. It does not identify an exact package release.
Two compatibility details are explicit: Shell.cwd is deprecated and ignored, and total_lines is the deprecated name for line_count in persistent-shell events. The capture does not establish the latest release or behavior outside this documentation snapshot.
Actions
Before integrating, confirm the package version and applicable migration guidance. Choose a workspace whose file, credential and process access matches the task; use isolation for untrusted commands. Configure command permissions, necessary environment variables, timeouts and appropriate output, log and file limits.
Verify behavior in the intended environment, especially rejected commands, timeout results, background-process cleanup, secret exposure and platform-specific tools. For the persistent shell tool, provide a way to read status files and clean up retained logs. These deployment checks remain unperformed.
