Pi
Learn how to use the Pi harness adapter.
The Pi harness adapter connects HarnessAgent to
@earendil-works/pi-coding-agent. Pi runs in the host Node.js process and uses
the sandbox as a remote filesystem and shell. It does not install a bridge
inside the sandbox.
Harness packages are experimental. Expect breaking changes between releases as this early API gets further refined.
Setup
$ pnpm add @ai-sdk/harness @ai-sdk/harness-pi @ai-sdk/sandbox-vercel
$ npm install @ai-sdk/harness @ai-sdk/harness-pi @ai-sdk/sandbox-vercel
$ yarn add @ai-sdk/harness @ai-sdk/harness-pi @ai-sdk/sandbox-vercel
$ bun add @ai-sdk/harness @ai-sdk/harness-pi @ai-sdk/sandbox-vercel
Import
pi is equivalent to createPi() with its default configuration.
Basic Usage
To use this agent, ensure environment variables include VERCEL_OIDC_TOKEN for
Vercel Sandbox, and one of the variables listed under authentication
for Pi.
Adapter Settings
Use createPi() to configure the runtime:
Settings:
auth: authentication mode (auto,openai,anthropic,custom, orai-gateway) or an isolated authentication environment.credentials: application-owned Pi credential storage. This replaces the file-backedauth.jsonstore and supports persistent database-backed credentials.extensionFactories: trusted inline Pi extension factories that run in the host Node.js process.mcpServers: MCP server definitions keyed by server name.providers: explicit Pi provider configurations for custom models.reattachInProcess: whether a suspended turn can reuse its live Pi session in the current process. Defaults totrue.thinkingLevel: Pi thinking level (off,minimal,low,medium,high,xhigh, ormax).
Inline Extensions
Use extensionFactories to load trusted inline Pi extensions for each harness
session:
Routine resource refreshes between turns reuse the active extension runtime and do not reinitialize factories. If the underlying Pi session is rebuilt, the factories initialize again for the new Pi runtime.
Extension factories execute in the host Node.js process with access to the host environment, so only pass factories you trust. This setting enables only the factories you explicitly provide. Filesystem extension discovery remains disabled, including user, project, and settings-based extensions. Themes and prompt templates also remain disabled.
Session Reattachment
By default, Pi keeps a suspended turn alive for an efficient continuation in the same process when the incoming request has compatible settings and runtime resources. Changed request-scoped settings or sandbox handles cause a cold restore from persisted lifecycle state.
For stateless or multi-replica applications, disable in-process reattachment so every continuation restores the persisted lifecycle state with the current request's settings:
An incoming completed resume-session state always takes precedence over an
older live suspended turn in the process.
Authentication
The auth setting selects which credentials Pi reads from the host environment:
auto(default): use AI Gateway credentials when available, then fall back to all provider credentials found in the environment.openai: useOPENAI_API_KEYand the optionalOPENAI_BASE_URL.anthropic: useANTHROPIC_API_KEYand the optionalANTHROPIC_AUTH_TOKENandANTHROPIC_BASE_URL.custom: register all providers configured through environment variables.ai-gateway: useAI_GATEWAY_API_KEYorVERCEL_OIDC_TOKENand the optionalAI_GATEWAY_BASE_URL.
If no applicable credential environment variable is set, the adapter attempts to resolve a native subscription from the host system unless AI Gateway authentication is selected.
Pass an authentication environment to use programmatically resolved
credentials without reading process.env:
The supplied record replaces the host environment for authentication discovery. Pi parses provider API keys and base URLs from that record.
For credentials managed outside environment variables or files, inject an application-owned credential store. Pi performs credential reads, refreshes, and updates through this interface:
credentials replaces Pi's auth.json storage. In request-scoped or
multi-replica deployments, pair it with reattachInProcess: false so each
continuation constructs a model runtime from the current request.
With custom, standard providers use environment variables such as
OPENAI_API_KEY, OPENAI_BASE_URL, ANTHROPIC_API_KEY, and
ANTHROPIC_BASE_URL. Other providers use a <PREFIX>_API_KEY and matching
<PREFIX>_BASE_URL pair.
Authentication variables do not identify a provider's API protocol or models. Register that metadata explicitly when using a custom model:
Sandbox
Pi needs a sandbox session but does not require exposed ports. You can create a Vercel network session or a local just-bash session:
Built-in Tools
The adapter exposes these common Pi built-ins through agent.tools:
readwriteeditbashgrepglobls
Additional Pi built-ins may also appear in agent.tools when they do not fit a
common tool shape.
Pi supports built-in tool approval requests when permissionMode is
allow-reads or allow-edits.
Known Limitations
Pi does not support structured output. Supplying output to HarnessAgent
causes the turn to throw HarnessCapabilityUnsupportedError.