Add `desktop` to `BoxdSandbox` for `ComputerUse`, driven by boxd's computer API
Part of #9347
This PR adds BoxdSandbox(desktop=True). It lets ComputerUse() (#11037) see and control the desktop of a boxd machine. Machines on boxd's current default image already have a desktop: the one the Desktop view of the boxd console shows. This PR drives it through boxd's computer API (machines.computer). The agent can type any text, including accented letters and emoji.
boxd's desktop starts as an empty screen. This PR adds a tint2 panel along the top with a labelled Terminal button that opens xterm below the panel, and a labelled Chromium button for boxd's own browser. So a model with only ComputerUse, and no shell tool, still has a usable desktop. boxd's desktop service is unchanged.
agent = Agent('anthropic:claude-opus-5-5', capabilities=[BoxdSandbox(desktop=True), Coder(), ComputerUse()])
How to review:
- Read the docstring at the top of
boxd_sandbox/_desktop.py. It lists how boxd's desktop behaves, as checked live. - Then read
BoxdDisplayDriver.actand_drag. They turn actions into boxd calls, and split them where boxd limits what one call takes. - Then read the panel and terminal scripts in
boxd_sandbox/_desktop.py, and where the backend installs and starts the panel.
Changes in this round
- Renamed for clarity, following the shared desktop code in #11040:
BoxdDisplayDriver,_computer_api,_panel_start_pending,_INSTALL_PANEL_PACKAGES,DESKTOP_LOG,_OPEN_TERMINAL_SCRIPT,_OPEN_BROWSER_SCRIPT,_RENAMED_KEYS, the_MAX_*_PER_CALLlimits, and others. - The panel's button style comes from the shared
TINT2_BUTTON_STYLEinstead of a copy. - Held input is released under the shared 5 s
RELEASE_TIMEOUTin_display.py, as on the other desktops. - Docs: "may be able to click and type" is gone.
- The live tests' real waits carry a
real-waitreason, which the test-wait check asks for. test_boxd_desktop.py47 passed.
What the PR adds
- Options.
BoxdSandbox.desktopandBoxdSandboxBackend(desktop=...)takeTruefor 1280x800, or(width, height). The default isFalse. - The desktop.
- It starts on the first action. On a new machine this takes about 3 seconds.
- The screen is fixed at the requested size with
set_screen_size. Someone watching in the console then sees it scaled, and can't resize the screen the agent clicks on. After the backend attaches again, the size is fixed again before any input. - The desktop also starts before each shell command, as on Docker (#11040). Commands get
DISPLAY=:100, the desktop's display. So a program the agent starts from the shell opens on the desktop (16f935b44a,test_a_shell_command_finds_the_desktop_running). agent-browser open <url>orxdg-open <url>from a shell opens boxd's browser. The docs say so.
- The panel.
- A
tint2panel along the top of the screen, with a button labelled Terminal, a button labelled Chromium when the machine hasagent-browser, and a button for each open window. Terminal opensxtermbelow the panel, filling the rest of the screen, with the keyboard focus. Chromium opens agent-browser's headed Chromium and moves it below the panel. - A new machine installs
tint2andxtermthrough the machine spec's.packages, as boxd boots it. An attached machine installs whichever is missing withapt-getthrough passwordlesssudo. - The panel starts with
boxd-desktop-launch, so boxd's desktop service is unchanged. - It starts on the first screen call only. Shell commands never wait for it. The first screen call waits for it, so the first screenshot shows it. Each restart of the display marks it due again.
- The start script takes a lock (with
flockwhen present), so two starts on one machine can't stack two panels. Atint2panel that already runs is left alone. - A panel that fails to start only logs a warning. The screen keeps working, and
/tmp/pydantic-ai-desktop.login the machine says why.
- A
- Long actions. If an action is more than boxd takes in one call, it is split into several calls. This applies to typing, scrolls, key repeats, and drags of more than 100 points.
- Refused before anything runs. boxd has no call that holds a key down across calls. So these raise
UnsupportedActionError:- a pointer move with modifier keys;
- a drag of more than 100 points with modifier keys.
- Errors. A value boxd refuses raises
WorkspaceError. A deleted or stopped machine raisesWorkspaceUnavailableError.
Design decisions
Use boxd's computer API, not our X11 driver. The first version of this PR installed the shared X11 desktop from #11040 on the machine. boxd's own API needs no X11 programs installed. It types any Unicode text, which our ASCII-only X11 driver can't. It also supports the side mouse buttons. DaytonaSandbox(desktop=True) makes the same choice in #11210.
Add a panel, not a second window manager. boxd's desktop runs xpra, which already acts as the window manager, so fluxbox exits there. tint2 and xterm do run, started with boxd-desktop-launch. The button is labelled Terminal because GPT-5.5 was slow to try a bare icon (see Live check).
Show boxd's own browser, not a new one. boxd's image already has agent-browser's Chromium, so the button opens that and installs nothing. It shows only when agent-browser exists, so an image without it gets no dead button (test_the_panel_has_a_browser_button_only_when_the_machine_has_agent_browser).
Start the panel on screen calls only. The display start runs before every shell command. When it included the panel install, a shell-only agent's first command waited up to about 30 seconds outside its own timeout. Now the start only fixes the screen size and marks the panel as due, and the next screen call starts it (fae17045af, test_a_command_does_not_wait_for_the_panel_but_the_next_look_does).
Fix the screen size with set_screen_size. Without it, someone who opens the Desktop view in the console could resize the screen while the agent uses it. The size is fixed again after the backend attaches again.
Split where boxd limits one call, and refuse only what can't be split.
- In one call, boxd takes at most 10,000 typed characters, 100 wheel clicks, 100 key repeats and 100 drag points.
- Splitting gives the exact same result for typing, scrolls and repeats.
- A drag of more than 100 points becomes a press, single moves, and a release. That can't hold modifier keys, so such a drag with modifiers is refused.
Leave the hold limit and the screen size to boxd. boxd itself refuses a hold of more than 5 minutes, so the display doesn't check it (74e6239795). A local size check that no measurement supported was dropped (28c8a1db24).
A long drag that fails releases the button. If that release also fails because the machine is gone, the run ends. Otherwise a button could stay pressed on a machine that the next call may reach.
Evidence
From the docstring in boxd_sandbox/_desktop.py, checked live on 2026-11-13:
| Behaviour | Measured |
|---|---|
| First computer call on a new machine | Starts the desktop in about 3 s, at 1280x800 |
| Typing 10,000 characters in one call | About 46 s. This is boxd's limit per call |
| Wheel clicks, key repeats, drag points per call | At most 100 each |
| Key names | X key names. Bare pause, numlock, scrolllock, numpad and media names are refused |
Live tests (tests/harness/boxd_sandbox/test_boxd_live.py):
| Behaviour | Test |
|---|---|
| The display contract | test_a_desktop_meets_the_display_contract |
Every key name PressKeys can send | test_the_desktop_takes_every_key_name |
| A program started from the shell opens on the desktop and takes any text, including more than 10,000 characters | test_a_program_started_from_a_command_opens_on_the_desktop_and_takes_any_text |
| Scrolls, key repeats and drags beyond what boxd takes in one call | test_boxd_takes_scrolls_key_repeats_and_drags_past_its_per_call_limits |
| Drags, key repeats and modifier keys reach a browser | test_drags_key_repeats_and_modifiers_reach_a_browser |
ComputerUse runs on a desktop machine | test_a_desktop_machine_runs_computer_use |
Live check
On 2026-11-20, with only BoxdSandbox(desktop=True) and ComputerUse(), and no shell or file tools. The task: "Report this machine's Linux kernel version and its free disk space on /." The truth, from exec on the same machine: uname -r is 6.18.0+, and df -h / shows 87G available.
| Model | Machine | Result | Requests | Time | Answer vs truth |
|---|---|---|---|---|---|
anthropic:claude-sonnet-5-5 | new | pass | 4 | 63 s | 6.18.0+, 87 GB free: matches |
openai-responses:gpt-5.5 | attached | pass | 11 | 87 s | 6.18.0+, 87G: matches |
anthropic:claude-sonnet-5-5 | attached | pass | 4 | 51 s | 6.18.0+, 87 GB free: matches |
openai-responses:gpt-5.5 | attached | pass | 12 | 77 s | 6.18.0+, 87G: matches |
Sonnet took a screenshot, clicked Terminal, typed the commands and zoomed to read them. GPT-5.5 first typed on the empty desktop and tried Ctrl+Alt+T and Alt+F2, then clicked Terminal.
Earlier setups, all with correct answers: with an icon-only launcher, Sonnet took 5 requests and GPT-5.5 took 7, 11 and 19. With the labelled button, GPT-5.5 took 8, 13, 8 and 3, and Sonnet took 4.
test_the_panel_opens_a_terminal_below_it_that_has_the_keyboard (tests/harness/boxd_sandbox/test_boxd_live.py) passed live after the review fixes. xterm opened at y=40, 1280 wide, and had the keyboard 1.0 s after the click.
Install time, measured 2026-11-20:
- New machine, through the spec: 30 s, including
apt-get update, frommachines.get(id).packages. - Attached machine without the spec: the panel start took 26.7 s, including
apt-get update. boxd's image needs the update: without it,apt-get installfails with "Unable to locate package tint2". - Two panel starts at once on one machine: both finished in 26.7 s, with one
tint2process.
Still rough:
- GPT-5.5 needs about 3 times as many requests as Sonnet, because it tries keyboard shortcuts before the Terminal button.
- On a new machine the spec install and the attached-machine fallback both run, and the second waits on apt's lock.
- A new X window can't be seen by
xdotool --onlyvisibleuntil the next computer call, so the terminal script checks without it and retries the focus. - An attached machine needs passwordless
sudofor the install. - Windows still have no title bars.
Known limits and follow-ups
- There is no live viewer. To watch a run, save each screenshot as it arrives.
- A fork or snapshot of an older image has no desktop. Use a new machine.
- boxd's desktop draws no title bars. An app started from the shell opens where it asks to, or at the top left.
- A second click on the Chromium button focuses the browser but can leave it under xterm, because xpra ignores raise requests.
- agent-browser's first start can be slower than a model's waits, so its first screenshots can be black.
Testing
- Unit tests run the SDK's own
AsyncComputerover a fake transport. They cover the exact boxd calls for each action, the refusals, long drags that fail or are cancelled, and attaching to a machine again. Panel tests cover the spec install, a start on each connection, a command that doesn't wait for the panel, a panel that fails to start, and a shell syntax check of the panel scripts. - Live tests against boxd's production cluster, as above.
What changes for existing users
Nothing changes for BoxdSandbox() without a desktop, because desktop defaults to False.
Merging
This PR builds on #11037, and on #11040 for LazyDisplay, the drag steps and the panel style.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.