Files
zeekay a7dbf44267 sandbox: a browser you can see and take over, and codex through the gateway; 1.3.8
The browser class ran Chromium in kiosk mode, so the pane showed one
page and no browser: no tabs, no address bar, nowhere to go.  It now
runs as an ordinary window, maximized, on the same DevTools port the
agent drives; the screen pane already passes mouse and keyboard
through, so a person can take it over.

Codex knew only its vendor: every `tool: codex` run went to
api.openai.com with no key and failed 401.  Its provider is now the
gateway, keyed by HANZO_API_KEY by name, and the build asserts codex
names it.

Claude-Session: https://claude.ai/code/session_015XYKLnBbrbajqj1GpRydF8
2026-11-06 22:41:34 -08:00

65 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# The browser class's program: Chromium, maximized with its own toolbar, on the
# display the desktop already started. Run as `sandbox-desktop browser`, so the X server, the window
# manager and the VNC pair are that script's business and this one only draws
# into them.
#
# A BROWSER IS A WINDOW, the way a phone is (avd.sh). The person watches it
# through the screen the fleet already serves (hanzoai/cloud apps/sandbox
# screen.go), and an agent drives it through the DevTools protocol on loopback:
# Playwright's `chromium.connectOverCDP("http://127.0.0.1:9222")`, run through
# the sandbox's exec. Both look at ONE Chromium, so what the agent does is what
# the person sees.
#
# LOOPBACK ONLY. A DevTools port is a remote control for every page the browser
# holds, cookies included, so it is bound to 127.0.0.1 and reached through exec
# like the VNC server is, never through the pod network.
#
# THE PERSON SEES A BROWSER AND CAN TAKE IT OVER. It runs as an ordinary window,
# maximized, with its tabs and address bar: a kiosk window showed one page and no
# way to go anywhere else, so a person watching an agent could see a page but not
# a browser, and could not type a URL into it. The screen pane passes the mouse
# and keyboard through (apps/sandbox/screen viewOnly false), so taking over is
# clicking into it.
#
# IT COMES BACK. A browser that crashes or is closed is started again on the same
# profile, so the pane and the agent never face a display with nothing on it.
set -euo pipefail
PORT="${SANDBOX_CDP_PORT:-9222}"
PROFILE="${SANDBOX_BROWSER_PROFILE:-${HOME}/.browser}"
START="${SANDBOX_BROWSER_START:-about:blank}"
SCREEN="${SANDBOX_SCREEN:-1280x800x24}"
WIDTH="${SCREEN%%x*}"
REST="${SCREEN#*x}"
HEIGHT="${REST%%x*}"
log() { printf '[browser] %s\n' "$*" >&2; }
mkdir -p "${PROFILE}"
# A profile left by a browser that did not exit cleanly holds a lock naming a
# process that is gone, and Chromium then refuses to start on it.
rm -f "${PROFILE}/SingletonLock" "${PROFILE}/SingletonSocket" "${PROFILE}/SingletonCookie"
while :; do
log "chromium on ${DISPLAY} at ${WIDTH}x${HEIGHT}, devtools on 127.0.0.1:${PORT}"
chromium \
--no-first-run \
--no-default-browser-check \
--disable-dev-shm-usage \
--password-store=basic \
--noerrdialogs \
--hide-crash-restore-bubble \
--disable-features=Translate \
--start-maximized \
--window-position=0,0 \
--window-size="${WIDTH},${HEIGHT}" \
--remote-debugging-address=127.0.0.1 \
--remote-debugging-port="${PORT}" \
--user-data-dir="${PROFILE}" \
"${START}" || true
log "chromium exited; starting it again"
rm -f "${PROFILE}/SingletonLock" "${PROFILE}/SingletonSocket" "${PROFILE}/SingletonCookie"
sleep 1
done