---
title: "OpenHands integration"
description: "Run OpenHands Agent Canvas in an E2B sandbox from the prebuilt openhands template, then open its web UI from your browser."
url: "https://e2b.dev/integrations/openhands-canvas"
---

# OpenHands

> Run OpenHands Agent Canvas in an E2B sandbox and open its web UI from your browser. The agent's shell commands, file edits and browsing stay in the sandbox.

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

## About this integration

- **Maintained by:** E2B
- **How it works:** Prebuilt openhands template
- **Template:** openhands
- **Language:** TypeScript, Python
- **Upstream:** [OpenHands/OpenHands · ★ 94k](https://github.com/OpenHands/OpenHands)
- **Example:** [e2b-cookbook/openhands-in-sandbox-python](https://github.com/e2b-dev/e2b-cookbook/tree/main/examples/openhands-in-sandbox-python)

## Get started

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

### Paste this into your coding agent

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

1. Install the e2b package using the project's package manager.
2. The SDK needs the E2B_API_KEY environment variable. If it isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode it. Generate a separate AGENT_CANVAS_API_KEY for the sandbox and never print it.
3. Follow the OpenHands guide at https://docs.e2b.dev/agents/openhands: create a sandbox from the openhands template that pauses on timeout, start agent-canvas --public in the background and wait for /health on port 8000.
4. Run it once and show me the Agent Canvas URL the sandbox returned.
```

## Or set it up yourself

### 1. Install the E2B SDK

```bash
npm i e2b
```

### 2. Set your keys

```bash
export E2B_API_KEY="e2b_..."
export AGENT_CANVAS_API_KEY=$(openssl rand -base64 32)
```

### 3. Start Agent Canvas in a sandbox

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

const apiKey = process.env.AGENT_CANVAS_API_KEY!

const sandbox = await Sandbox.create('openhands', {
  timeoutMs: 60 * 60 * 1000,
  lifecycle: { onTimeout: 'pause', autoResume: true },
})

const canvas = await sandbox.commands.run(
  'agent-canvas --public > /tmp/agent-canvas.log 2>&1',
  {
    background: true,
    timeoutMs: 0,
    envs: { LOCAL_BACKEND_API_KEY: apiKey },
  }
)
await canvas.disconnect()
```

### 4. Open the web UI

```typescript
const url = `https://${sandbox.getHost(8000)}`
while (!(await fetch(`${url}/health`).then((r) => r.ok, () => false))) {
  await new Promise((resolve) => setTimeout(resolve, 2000))
}

console.log(`Agent Canvas: ${url}`)
```

## What runs in the sandbox

Agent Canvas and everything the agent does run in the sandbox, away from your machine.

- **Code:** Agent Canvas, the OpenHands Agent Server and Chromium, preinstalled. The agent runs shell commands, edits files and browses the web there.
- **State:** Conversations, settings and workspaces live under /home/user/.openhands in the sandbox. Logs go to /tmp/agent-canvas.log.
- **Lifetime:** With onTimeout: 'pause' and autoResume, the sandbox pauses at its timeout and wakes on the next request to its URL.
- **Access:** Public mode asks for your Agent Canvas API key, so only people you share it with can use the agent.

## More coding agents

Other coding agents that run in E2B sandboxes.

- [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.
- [OpenAI Codex](https://e2b.dev/integrations/codex.md): Run OpenAI's Codex CLI headless in a sandbox and collect the diff when it's done.
- [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.

## Links

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