openhands template with Agent Canvas, its Python services, and Chromium already installed, so you can run the agent in an E2B sandbox without installing it yourself.
Start Agent Canvas
The script below creates a sandbox, starts Agent Canvas in public mode, and waits for its/health endpoint on port 8000 before it prints the URL. Generate the Agent Canvas API key yourself and pass it in AGENT_CANVAS_API_KEY, for example with export AGENT_CANVAS_API_KEY=$(openssl rand -base64 32). Don’t print or log the key. Public mode makes the UI ask for the key, so only people you share it with can use the agent. Use a different key for every sandbox.
/home/user/.openhands in the sandbox. Its logs are in /tmp/agent-canvas.log.
The agent can run shell commands, edit files, and browse the web inside the sandbox. E2B isolates those actions from your machine, so the agent cannot reach your host files or credentials unless you pass them in. Sandboxes can reach the internet by default — restrict outbound traffic with network rules when the agent handles untrusted input or secrets. Hostname rules apply to HTTP(S) traffic only; use CIDR rules for other protocols.
Timeouts and pausing
By default, the sandbox is killed when its timeout expires, and your conversations and workspace are lost with it. The example above setsonTimeout: 'pause' so the sandbox pauses instead, and autoResume: true so it wakes up on the next request to its URL. See Auto-resume for details.
The agent’s work does not extend the timeout, and neither do requests to the sandbox URL, including those from the Agent Canvas UI. When the timeout expires, the sandbox pauses with its memory and processes intact:
- With Agent Canvas open in a browser tab, the UI resumes the sandbox within seconds and the conversation continues.
- With nobody connected, the agent waits while the sandbox is paused and continues when you open the URL again. Scheduled automations don’t run while the sandbox is paused.
sandbox.kill().
Use the sandbox as a backend for your local Agent Canvas
Agent Canvas can switch between several backends. To keep the UI on your machine and run the agent in E2B, start only the backend in the sandbox. Start it the same way as in the example above, with--backend-only added and LOCAL_BACKEND_API_KEY set to your key:
Build a custom template
If you need to customize the environment (e.g. pre-install dependencies, add config files), build your own template on top of the pre-builtopenhands template.
my-openhands instead of openhands, and start Agent Canvas as shown above.
Related guides
Cookbook example
Fix a failing test in a small Python project from code and print the diff
Auto-resume
Pause on timeout and wake up on the next request
Sandbox persistence
Auto-pause, resume, and manage sandbox lifecycle
Internet access
Control the sandbox’s outbound network access