Add `DockerContainer(desktop=True)` for computer use
Part of #9347
This PR adds DockerContainer(desktop=True): a local Docker container with a graphical desktop, so ComputerUse() (#11037) has a screen to see and control. It also adds the X11 code every Xvfb desktop sandbox shares: the xdotool driver, the start script, and a display that starts the first time it's needed. The agent also gets the container's shell and files, so Coder and ComputerUse can work on the same machine.
This PR now includes the X11 provisioning work from #12963: the start script installs the display's programs on a sandbox that lacks them, and the panel gets a button for the image's own browser. The sandbox PRs (#11210, #11211, #12968, #12964, #12965, #12966, #12967, #13986, #13987, #13988) each build on this PR directly.
agent = Agent('anthropic:claude-sonnet-5-5', capabilities=[DockerContainer(desktop=True), ComputerUse()])
How to review:
- Read
_x11.py. It turns each action into anxdotoolcommand, releases held keys and buttons when an action fails, and holds the start script. - Then read
_display.py.LazyDisplaystarts the display on first use or before a shell command, and decides what to retry. - Then read
_drag.pyand the desktop parts ofdocker_container/_backend.py.
What the PR adds
- Options.
desktop=Truegives a 1280x800 screen. For another size, passdesktop=(width, height). It works onDockerContainerandDockerContainerBackend. - The image. Without an
image, the first run buildspydantic-ai-desktop:<hash>fromDESKTOP_DOCKERFILE, and later runs reuse it. It has Debian, Xvfb, fluxbox, a tint2 panel with Terminal and Firefox buttons, and CJK fonts.DESKTOP_DOCKERFILEis exported frompydantic_ai_harness.docker_container. - Images without the programs. When the display first starts and a program is missing, the start script installs
xvfb xdotool x11-utils scrot util-linuxwithapt-get, as root or through passwordlesssudo. Without either, the error names what's missing. The desktop's own programs (fluxbox tint2 xterm) are a separate install, so one the package lists lack never stops the display. - The panel. A labelled Terminal button comes first. If the image has a browser (
firefox-esr,firefox,chromium,chromium-browserorgoogle-chrome), it gets a labelled button after it. Chromium and Chrome get--no-sandboxonly as root or when user namespaces don't work. - The display. It starts on first use or before the first shell command, whichever comes first. Starts at the same time share one X server, under a lock. Shell commands get
DISPLAY, so a program the agent starts opens on the desktop. The first screenshot waits for the panel, so it isn't black. - Input. Actions run through
xdotool; screenshots and zoom throughscrot. Typing is ASCII only: any other character fails the action, with a message the model reads.
Design decisions
Build the image on first use, not publish one. We host nothing and keep nothing patched. The cost is a slower first run. The image is cached, so the docs show the rebuild command (--pull --no-cache) for security updates.
The host's network is documented, not refused. With --network host, programs in the container could reach an X server on the host through Linux's abstract socket. Xvfb starts with -nolisten tcp -nolisten local, so our own X server listens only on its socket file. The start also fails when another X server already answers on display :1 through a shared network. The docs and THREAT_MODEL.md say not to put a desktop container on the host's network. An earlier version read the container's NetworkMode and refused; that check is cut, since the two guards above already keep xdotool off a foreign X server.
Start Xvfb with -noreset. Without it, the X server resets each time an xdotool command exits while no window manager runs. A reset moves the pointer to the middle of the screen and releases held buttons.
Start the display before each shell command. The instructions tell the model that a program it starts from the shell opens on the screen. So every shell command starts the display, outside the backend's lock. File operations that use the shell also start it, so a broken desktop makes them fail too.
ASCII-only typing. To type a character with no key, such as é, xdotool remaps a spare key for each keystroke. Chrome reads the key map afterwards and gets a different character, or none. Refusing the action tells the model why.
LazyDisplay holds the start and retry rules for every harness desktop. Creating it starts nothing. A call that only looks, such as a screenshot, is retried once after a failure, which restarts a lost display. An action is never retried, so nothing is done twice.
Drags move in steps. A drag presses, moves in steps of at most 200 pixels (at least two), 50 ms apart, then moves 1 pixel past the end and back before releasing. Chromium answers each pointer position with what the page said about an earlier one, so without one more position after the page accepts the drop, it cancels the drop on release. A web page's drag-and-drop can still miss a drag now and then; the docs say so.
One builder for every Xvfb backend. x11_display(run_command, size, describe_environment) returns the LazyDisplay, or None without a desktop. Each backend sets DISPLAY in its own env in one line.
Changes in this round
- Drags: the press pause is gone, and the drag ends with a 1-pixel move past the end and back.
- One
x11_display()builder replacesx11_display()plusdesktop_display(). - The Docker host-network refusal, the Firefox
policies.json,ca-certificatesand the emoji font are cut. - The release timeout is one 5 s
RELEASE_TIMEOUTin_display.py, which the X11, Daytona and boxd drivers share. - Clearer names across
_x11.pyand_display.py(checked_desktop_size,DEFAULT_DESKTOP_BASE_IMAGE,mark_stopped,operation=,TINT2_BUTTON_STYLE), and the test-onlyscreen()helper is nowfull_display(). - The two live-test waits flagged in review carry a
real-waitreason, andtest_x11.pyno longer patches a private limit: it types 20,000 characters and drags through 2,500 points instead.
Evidence
| Measurement | Result |
|---|---|
| Time per wheel click, used in the scroll's time limit | 20 ms |
Rebuilding after docker rmi without --no-cache | Shows CACHED and keeps the old layer |
| Panel start without waiting for a window manager | tint2 waits about 16 s for one |
A Daytona sandbox (uid 1001, no xdotool, no /tmp/.X11-unix) and an E2B desktop starting through the install path | 7 s and 9 s |
Live tests (tests/harness/docker_container/test_docker_live.py), each event observed with xev: the display contract, the first screenshot isn't black, key names arrive as their X key names, buttons 1, 2, 3, 8 and 9, one wheel click per scroll step, a drag holds the button the whole way, a cancelled action releases what it pressed, and typed text reaches the focused window.
Live runs (2026-11-20, ComputerUse only, no shell; task P is "latest Python on python.org", task E is "title of example.com"; requests per run):
| Image | Panel | Sonnet P | Sonnet E | GPT P | GPT E | Browser use |
|---|---|---|---|---|---|---|
| Docker default | Terminal, Firefox | 5 | 3 | 6 | 5 | All 4 clicked Firefox at step 2. All correct. |
| Docker, Chromium-only image | Terminal, Chromium | 7 | 4 | 6 | 5 | All 4 clicked Chromium at step 2. All correct. |
Known limits and follow-ups
- There is no live viewer. To watch a run, save each screenshot as it arrives. The docs show how.
- A screenshot whose base64 text is over 10 MiB goes past the backend's output limit. Only near-random pixels get that large.
- Containers keep running after a run, as with
DockerContainertoday. The docs show how to clean them up. - The start script installs the display's programs as root.
THREAT_MODEL.mdsays so; a maintainer may want to weigh in on that design.
Testing
- Unit tests with a fake
dockerCLI,LazyDisplayagainst a fake driver, and the X11 driver against scripted command results (test_x11.py62 passed,test_docker_desktop.py52 passed;_x11.py,_display.pyand_drag.pyat 100% branch coverage). - Live tests on Docker as above.
Merging
This PR builds on #11006 and #11037. Merge it before the sandbox PRs listed above.
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.