Add `LocalDesktop`: a screen on this Linux machine for computer use

Draft
AD
11d ago
+15661-236

Adds LocalDesktop, a LocalWorkspace with a screen, so ComputerUse runs on this Linux machine without Docker or a cloud sandbox.

agent = Agent(model, capabilities=[LocalDesktop('.'), Coder(), ComputerUse()])

What changes for users:

  • By default the screen is a private, invisible Xvfb with fluxbox, started on first use, at size= (1280x800 by default). Only the agent's commands can connect to it.
  • Later and concurrent runs of the same LocalDesktop share that screen and see the windows earlier runs left. It stops when the program exits; if only the window manager exits, it starts again and the windows stay.
  • Commands run on the screen too, so an app the agent starts through Coder or workspace.run opens there.
  • real_screen=True drives the X session you're logged in to, on both LocalDesktop and LocalDesktopBackend. Modifier keys you hold are left alone.
  • Refused with a WorkspaceUnavailableError at the first display call (commands still run): non-Linux, a Wayland session, no DISPLAY for real_screen, missing programs (the message names the apt packages).
  • LocalDesktopBackend and VirtualScreen are public for workspace= use. Backends given no screen share one private 1280x800 screen in the process, so building one per run starts one screen; pass screen=VirtualScreen(size) for one of its own and await screen.stop() to stop it.

Shared code (_x11.py, used by the Docker and E2B desktops):

  • X11Computer no longer sets DISPLAY; the backend's commands carry it (Docker and E2B already did).
  • X11Computer(release_modifiers=False) skips releasing stuck modifiers before each action, for a screen a person is using.

Decisions:

  • One private screen per capability instance, not per run (documented, with "give each concurrent user its own LocalDesktop").
  • One spelling for the real screen, real_screen=True, matching how DockerSandbox and its backend share desktop=; screen= takes only a VirtualScreen, and passing both is refused.
  • Linux X11 only. Wayland (portal and libei, with a consent dialog) and macOS (ScreenCaptureKit and Quartz events) are follow-ups that don't change this API.
  • Screen processes are plain Popens under setpriv --pdeathsig, started from one long-lived thread, so the screen survives each run_sync event loop and stops with the program.

Tested:

  • Unit tests with fake X programs on PATH (screen tests skip off Linux; run in a Debian container: 71 passed), including three backends given no screen starting one Xvfb (fails without the fix).
  • Ubuntu 24.04 container with real Xvfb, fluxbox and xdotool: workspace conformance suite against LocalDesktopBackend; checks by effect in a real app on the private screen and on a stand-in logged-in session (unicode typing, click to focus, drag, double-click selection, scroll, pointer position, two screens, restart after the X server is killed, across event loops, Wayland refused).
  • End to end with ComputerUse: Claude Sonnet 5.5, GPT-5.5 and Gemini 3.8 Flash each typed a command whose output had to reach a file.

Depends on: #11211 (pydantic_ai_harness._x11.X11Computer and the moved tests/harness/test_x11.py), so #11006, #11037 and #11040 too. Does not need #11210, #11038 or #11039. Merge order: last on the desktop track.

What to look at:

  • local_desktop/_backend.py: VirtualScreen start, stop and restart; the shared default screen; every command starts the private screen (a screen that can't start costs up to 10 s per command, then the command runs without it).
  • real_screen vs the private default, and the screen= parameter on the backend.
  • _x11.py: DISPLAY now comes from each backend's command env.

šŸ¤– Generated with Claude Code