Skip to main content

Coding agents

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.

Maintained by
E2B
How it works
Prebuilt openhands template
Template
openhands
Language
TypeScript, Python

Set it up

Get started

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

Paste this into your coding agent

Run OpenHands in an E2B sandbox from this project.

  1. 1.Install the e2b package using the project's package manager.
  2. 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. 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. 4.Run it once and show me the Agent Canvas URL the sandbox returned.

Or set it up yourself

  1. 1. Install the E2B SDK

    npm i e2b
  2. 2. Set your keys

    export E2B_API_KEY="e2b_..."
    export AGENT_CANVAS_API_KEY=$(openssl rand -base64 32)
  3. 3. Start Agent Canvas in a sandbox

    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. 4. Open the web UI

    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}`)

Security

What runs in the sandbox

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

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

3B+ sandboxes started

Give every agent a machine