---
title: "Pi integration"
description: "Run the Pi coding agent in an E2B sandbox from the prebuilt pi template. Use print mode headless and keep its file and shell tools off your machine."
url: "https://e2b.dev/integrations/pi"
---

# Pi

> Run the Pi coding agent in a sandbox from the prebuilt pi template. Pi reads, edits and runs commands without prompts, so the sandbox keeps all of it off your machine.

Coding agents · [All integrations](https://e2b.dev/integrations.md)

## About this integration

- **Maintained by:** E2B
- **How it works:** Prebuilt pi sandbox template
- **Package:** e2b
- **Language:** TypeScript, Python
- **Upstream:** [earendil-works/pi · ★ 123k](https://github.com/earendil-works/pi)
- **Docs:** [docs.e2b.dev/agents/pi](https://docs.e2b.dev/agents/pi)

## Get started

Paste the prompt into your coding agent, or follow the steps yourself.

### Paste this into your coding agent

```text
Run Pi in an E2B sandbox from this project.

1. Install the e2b SDK using the project's package manager.
2. The SDK needs the E2B_API_KEY environment variable, and Pi needs a model provider key such as ANTHROPIC_API_KEY. If E2B_API_KEY isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode either key.
3. Follow the Pi guide at https://docs.e2b.dev/agents/pi: create a sandbox from the pi template, pass the provider key in envs, and run pi -p "<task>" in print mode. Kill the sandbox when it's done.
4. Run one task and show me the output that came from the sandbox.
```

## Or set it up yourself

### 1. Install the E2B SDK

```bash
npm init -y && npm pkg set type=module
npm install e2b
npm install -D tsx
```

### 2. Set your API keys

```bash
export E2B_API_KEY="e2b_..."
export ANTHROPIC_API_KEY="..."
```

### 3. Run Pi in print mode

```typescript
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('pi', {
  envs: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
})

const result = await sandbox.commands.run(
  `pi -p "Create a hello world HTTP server in Go"`
)

console.log(result.stdout)
await sandbox.kill()
```

## What runs in the sandbox

Pi and every file edit and shell command it makes stay inside the sandbox.

- **Agent:** Pi in print mode. It shows no permission prompts for its built-in tools, so none need auto-approving.
- **Files:** The repo you clone and every change Pi makes. Read the result back with git diff.
- **Secrets:** Pi can't reach your host files or credentials. Only the provider key you pass in envs is there.
- **Network:** Internet access is on by default. Limit it with outbound rules by CIDR or hostname.

## More coding agents

Other coding agents that run in E2B sandboxes.

- [OpenCode](https://e2b.dev/integrations/opencode.md): Run OpenCode in a sandbox, or keep it local and point its workspaces at E2B with the @e2b/opencode plugin.
- [Hermes Agent](https://e2b.dev/integrations/hermes.md): Run Hermes Agent in a sandbox template, or keep it local and execute its terminal tools on E2B.
- [Claude Code](https://e2b.dev/integrations/claude-code.md): Run Claude Code in its own sandbox with a real filesystem, terminal, and git, so it can work unattended.

## Links

- [Get API key](https://console.e2b.dev/?tab=keys)
- [Read the docs](https://docs.e2b.dev/agents/pi)
- [E2B documentation](https://docs.e2b.dev)
