Skip to main content

Desktop, browser and ports

A process inside a sandbox can listen on a port: a desktop viewer, a browser's DevTools endpoint, a dev server. A port URL reaches that port from outside over HTTPS, WebSockets included, with no inbound port opened on the sandbox. Use it to:

  • watch an agent work on a Linux desktop in your browser, or take over the mouse and keyboard;
  • drive the sandbox's Chromium from Playwright or Puppeteer over the DevTools protocol (CDP);
  • open a web app the agent is running, before it is deployed anywhere.

Create a port URL​

curl -X POST "$API/sandbox/port-url" \
-H "Authorization: $TOKEN" -H 'Content-Type: application/json' \
-d '{"accountId": "ACCOUNT_ID", "sandboxId": "SANDBOX_ID", "port": 6080, "ttlSeconds": 3600}'
{
"success": true,
"url": "https://p6080-3f2a9c0d1e5b7a4c8d2e.REGION_DOMAIN/p/qsb1..../",
"port": 6080,
"expiresAt": "2026-10-11T13:00:00.000Z"
}

MCP: create-sandbox-port-url.

  • port is any port from 1024 to 65535 that a process in the sandbox listens on (on 127.0.0.1 or 0.0.0.0). 8890 is reserved.
  • The URL has the shape https://p<port>-<id>.<region domain>/p/<credential>/. Each port of each sandbox has its own host, so it is its own browser origin: pages served through different port URLs cannot read each other's storage, cookies or service workers.
  • The URL carries its own credential in the path, and that credential reaches only this port of this sandbox. It cannot run commands or read files. Anyone holding the URL can use the port until it expires, so share it like a password.
  • ttlSeconds (60 to 86400, default 3600) bounds when the URL accepts new connections. A connection that is already open, such as a desktop viewer, keeps working after that. To reconnect later, create a new URL.
  • A paused sandbox is resumed first (409 with data.retryable: true while that is in progress).
  • If nothing listens on the port, the URL answers 502 with error: "port_unreachable".
  • Pages served through the URL get Referrer-Policy: no-referrer, so the credential does not leak to other sites through links.

A Linux desktop with Chromium​

This image gives a sandbox a desktop (XFCE on a virtual display) with Chromium, a browser viewer for it (noVNC), and the Chromium DevTools endpoint. It also has xdotool, scrot and ffmpeg for agents that click, type, take screenshots or record the screen. Every component is an unmodified Debian package.

Dockerfile:

# Agent Sandbox image: Linux desktop with Chromium, viewable in a browser.
#
# Xvfb (virtual display) + XFCE + x11vnc + noVNC/websockify + Chromium with the
# DevTools protocol (CDP) on loopback, plus xdotool/scrot/ffmpeg for agents
# that drive the desktop with mouse, keyboard, screenshots and recordings.
# Same recipe as E2B Desktop (Apache-2.0) and Anthropic's computer-use demo
# (MIT). Every component is an unmodified Debian package; the GPL ones
# (x11vnc, Xvfb) run as separate programs. Source: https://sources.debian.org.
#
# Start it inside the sandbox with a long-running command (the runtime agent is
# PID 1, so the image CMD does not run): start-sandbox-command with
# ["/usr/local/bin/desktop-start"]. Then create port URLs
# (POST /api/public/v1/sandbox/port-url, MCP create-sandbox-port-url) for:
# 6080 noVNC, full control (open the URL itself)
# 6081 noVNC, view only (open the URL itself) - enforced by x11vnc -viewonly
# 9222 Chromium CDP (/json/version, /devtools/browser/<id>)
FROM debian:bookworm-slim

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
xvfb x11vnc novnc websockify \
xfwm4 xfce4-panel xfdesktop4 xfce4-terminal xfce4-settings dbus-x11 \
chromium fonts-dejavu-core fonts-liberation fonts-noto-cjk \
xdotool scrot ffmpeg x11-utils \
ca-certificates curl procps \
&& rm -rf /var/lib/apt/lists/*

# Opening the port URL itself lands on the desktop: index.html forwards to
# vnc.html with the WebSocket path relative to the URL's own prefix.
COPY index.html /usr/share/novnc/index.html

COPY desktop-start /usr/local/bin/desktop-start
RUN chmod 0755 /usr/local/bin/desktop-start \
&& useradd -m -u 1001 -s /bin/bash agent \
&& mkdir -p /workspace && chown 1001:1001 /workspace

ENV DISPLAY=:1 \
DESKTOP_RESOLUTION=1280x800x24
USER 1001
WORKDIR /workspace
CMD ["/usr/local/bin/desktop-start"]

index.html sends the browser straight into the viewer. noVNC builds its WebSocket address from the site root, so behind the port URL it needs the path spelled out:

<!doctype html>
<meta charset="utf-8">
<title>Desktop</title>
<script>
// noVNC builds its WebSocket URL from the site root, so behind a path prefix
// (the sandbox port URL /p/<token>/) it must be told the full relative path.
var dir = location.pathname.replace(/^\//, '').replace(/[^/]*$/, '');
location.replace('vnc.html?autoconnect=1&reconnect=1&resize=scale&path=' +
encodeURIComponent(dir + 'websockify'));
</script>

desktop-start starts everything and stays in the foreground:

#!/bin/sh
# Starts the desktop and stays in the foreground while it runs. Logs go to
# $DESKTOP_LOG_DIR (default /tmp/desktop). Safe to run again: it exits early
# when the display is already up.
set -eu
export DISPLAY="${DISPLAY:-:1}"
export HOME="${HOME:-/home/agent}"
RES="${DESKTOP_RESOLUTION:-1280x800x24}"
LOG="${DESKTOP_LOG_DIR:-/tmp/desktop}"
CDP_PORT="${DESKTOP_CDP_PORT:-9222}"
mkdir -p "$LOG"

if xdpyinfo >/dev/null 2>&1; then
echo "desktop already running on $DISPLAY"
exit 0
fi

Xvfb "$DISPLAY" -screen 0 "$RES" -nolisten tcp >"$LOG/xvfb.log" 2>&1 &
i=0
until xdpyinfo >/dev/null 2>&1; do
i=$((i + 1)); [ "$i" -gt 100 ] && { echo "Xvfb did not start"; cat "$LOG/xvfb.log"; exit 1; }
sleep 0.1
done

dbus-launch --exit-with-session sh -c 'xfwm4 & xfdesktop & xfce4-panel & wait' >"$LOG/xfce.log" 2>&1 &

# Two VNC servers on the same display, loopback only: 5900 accepts input,
# 5901 is view-only on the server side (a client cannot override it).
x11vnc -display "$DISPLAY" -rfbport 5900 -localhost -forever -shared -nopw -quiet >"$LOG/x11vnc.log" 2>&1 &
x11vnc -display "$DISPLAY" -rfbport 5901 -localhost -forever -shared -nopw -viewonly -quiet >"$LOG/x11vnc-view.log" 2>&1 &
websockify --web /usr/share/novnc 6080 127.0.0.1:5900 >"$LOG/novnc.log" 2>&1 &
websockify --web /usr/share/novnc 6081 127.0.0.1:5901 >"$LOG/novnc-view.log" 2>&1 &

# gVisor is the isolation boundary, so Chromium's own sandbox (which needs user
# namespaces) is off, and --test-type hides the banner that flag causes. CDP
# listens on loopback: a port URL with a port-scoped token is the only way in.
chromium --no-sandbox --test-type --disable-dev-shm-usage --no-first-run --no-default-browser-check \
--user-data-dir="$HOME/.chromium" --remote-debugging-address=127.0.0.1 \
--remote-debugging-port="$CDP_PORT" --remote-allow-origins='*' \
--window-position=0,0 --window-size=1280,760 about:blank >"$LOG/chromium.log" 2>&1 &

echo "desktop up on $DISPLAY: noVNC 6080 (control), 6081 (view only), CDP $CDP_PORT"
wait

Build and push it, then create a template revision with its digest. 4 zClouds (2 vCPU, 2 GB) is enough for the desktop and a few tabs.

Use it​

  1. Start the desktop with a long-running command. The runtime agent is the sandbox's main process, so the image's own command does not start it:

    curl -X POST "$API/sandbox/command/start" \
    -H "Authorization: $TOKEN" -H 'Content-Type: application/json' \
    -d '{"accountId": "ACCOUNT_ID", "sandboxId": "SANDBOX_ID", "command": ["/usr/local/bin/desktop-start"], "idempotencyKey": "desktop-SANDBOX_ID"}'

    While this command runs, the sandbox is not terminated for idleness, even if the only traffic is someone watching the desktop. The maximum lifetime still applies.

  2. Create port URLs for what you need:

    PortWhat it isOpen
    6080Desktop, with mouse and keyboardthe URL itself
    6081Desktop, view only (input is ignored by the server)the URL itself
    9222Chromium DevTools (CDP)<url>json/version, <url>devtools/browser/<id>
  3. Connect an automation tool to the browser. Chromium reports a ws://127.0.0.1:9222/... address in json/version; keep its path and put it after your port URL:

    import { chromium } from 'playwright';

    const base = 'https://p9222-3f2a9c0d1e5b7a4c8d2e.REGION_DOMAIN/p/qsb1..../'; // port 9222
    const { webSocketDebuggerUrl } = await (await fetch(`${base}json/version`)).json();
    const path = new URL(webSocketDebuggerUrl).pathname.slice(1);
    const browser = await chromium.connectOverCDP(base.replace('https', 'wss') + path);
    const page = browser.contexts()[0].pages()[0];
    await page.goto('https://example.com');

    What the agent does in the browser shows up live in the desktop viewer.