Skip to main content
Agents

Pi

Run the Pi coding agent as a durable Rivet Actor.

This integration is in beta. APIs may change between releases.

@rivet-dev/pi runs the Pi coding agent in a Rivet Actor. The agent loop runs in the actor. Pi’s file and shell tools run in a separate sandbox.

Each actor holds one Pi session and saves it in its SQLite database, so a conversation survives sleep and restarts.

YOUR BACKENDSANDBOXESPi actorShell + filesagent loop + SQLiteSleepingPausedTool callsModel callsModel provider

Quickstart

Install

npm add @rivet-dev/pi rivetkit

Define the actor

import { pi } from "@rivet-dev/pi";
import { setup } from "rivetkit";

const agent = pi({ model: "anthropic/claude-opus-5-5" });

export const registry = setup({
	use: { agent },
});

registry.start();

Set the key for your model provider, such as ANTHROPIC_API_KEY.

Add a sandbox

Pi’s file and shell tools run in a sandbox. Without one they are disabled.

npm add @rivet-dev/sandbox-adapter @rivet-dev/agentos
import { agentOS } from "@rivet-dev/agentos";
import { pi } from "@rivet-dev/pi";
import { agentOSProvider } from "@rivet-dev/sandbox-adapter/agentos";
import { setup } from "rivetkit";

const agent = pi({
	model: "anthropic/claude-opus-5-5",
	sandbox: agentOSProvider({ actor: "vm" }),
});

export const registry = setup({ use: { agent, vm: agentOS() } });

To use another provider, install its SDK and pass its provider instead. Provider credentials never enter the sandbox.

ProviderImport from @rivet-dev/sandbox-adapterSDK
E2Be2bProvider from /e2be2b
DaytonadaytonaProvider from /daytona@daytonaio/sdk

For another provider, implement SandboxProvider. See e2b.ts for an example.

Send a prompt

import { createClient } from "rivetkit/client";
import type { registry } from "./server";

const client = createClient<typeof registry>("http://localhost:6420");
const agent = client.agent.getOrCreate(["support", "customer-123"]);

const conn = agent.connect();

await conn.prompt("Inspect the project and summarize its test failures.");
console.log(await conn.getLastAssistantText());

await conn.dispose();

The client waits for Pi to finish, then reads the full reply with getLastAssistantText().

Deploy

By default, Rivet stores Actor state on the local file system.

To scale Rivet in production, pick how much of it you want to run yourself:

If you are running your own workers, follow the guide for your hosting provider:

Configuration

The Pi actor accepts every actor() option and Pi’s session options, such as thinkingLevel, tools, and customTools. It also accepts:

OptionDescription
modelModel for a new session, as provider/modelId.
scopedModelsModels a client may switch to with setModel.
apiKeysAPI keys by provider. Defaults to the environment.
providersCustom providers, in the shape of Pi’s models.json.
credentialsLogins your application stores. See Bring your subscription.
sandboxWhere Pi’s file and shell tools run. See @rivet-dev/sandbox-adapter.
settingsPi settings for a new session.

Each run is traced as an invoke_agent pi span with OpenTelemetry GenAI attributes, without prompts or tool data. See OpenTelemetry to export traces.

Bring your subscription

Your users can run Pi on their own Claude or ChatGPT subscription instead of your API key.

const agent = pi({
	model: "openai-codex/gpt-6-astra",
	// c.key[0] is the user id, so each user has one credentials actor.
	credentials: (c) =>
		c.client<Registry<{ credentials: typeof credentials }>>().credentials.getOrCreate([c.key[0]]),
});

See the credentials actor implementation.

Make sure to protect the credentials actor with authentication, because its actions return provider tokens.