Add `desktop` to `OpenSandbox` for `ComputerUse`
Part of #9347. Builds on #11040.
This PR adds OpenSandbox(image=..., desktop=True), which lets ComputerUse() (#11037) see and control a screen inside a sandbox on your own OpenSandbox server. It uses the shared X11 driver from #11040, the same one E2B uses.
agent = Agent(
'anthropic:claude-opus-5-5',
capabilities=[OpenSandbox(image='debian:bookworm-slim', desktop=True), Shell(), ComputerUse()],
)
How to review: opensandbox_sandbox/_backend.py: __init__, run and the new _run_argv. The rest is the capability field, docs and tests.
What the PR adds
- Options.
OpenSandbox.desktopandOpenSandboxBackend(desktop=...)takeTruefor 1280x800, or(width, height). The default isFalse. Specs can set it. - The screen. It runs in your
image. When the image's user is root, the first use installs any missing X programs withapt-get, through the shared start script. (The Docker runtime's defaultno_new_privilegesblockssudo.) Otherwise the first use raisesWorkspaceUnavailableErrornaming what is missing. - Shell commands see it.
run()starts the display before each command and addsDISPLAY=:1, so a program the agent starts from the shell opens on the screen. The display's own commands go through_run_argv, which doesn't start it. - No port. The backend never calls
get_endpointfor the screen and opens no port. The X server listens on no TCP or local socket. - execd. Every screen action is a command, so the docs say to use execd 1.2 or later: older versions take about a second per command.
- Docs. A "Give the agent a desktop" section on the OpenSandbox page and README, a
desktoprow in the configuration table, a row inComputerUse's "Where the screen comes from" table, and the harness skill reference.
Design decisions
Use the shared X11 driver, as E2B does. OpenSandbox has no computer API, and it runs whatever image the user names, so the start script either installs into it or refuses.
Refuse rather than approximate. A non-root image without the programs gets an error naming them, not a partial screen.
Start the display before each shell command. This is the decision from #11040.
Tests
tests/harness/opensandbox_sandbox/test_opensandbox_desktop.py, against the existing fake server. The fake gets a display hook that answers the X commands with the shared FakeDisplay, routed by FakeDisplay.answers. Every other command still runs for real.
- a shell command finds the desktop running, with
DISPLAYand the user'senv; - a desktop size reaches the display it starts;
- a reattached desktop sandbox gets its display back, and a non-desktop one has none;
OpenSandbox(desktop=True)plusComputerUseruns the computer tool, and the only endpoints looked up are the two the SDK always asks for (execd and the egress sidecar).
test_opensandbox_sandbox.py adds desktop to the spec schema list and the from_spec round trip.
Live check
On a local OpenSandbox server (Docker runtime, execd 1.2), image debian:bookworm-slim running as root, with ComputerUse and the sandbox only, no shell (2026-11-23). The task: "Open a terminal, type echo hello-desktop, press Enter, and tell me what the terminal shows." In each run the final screenshot shows the command, hello-desktop and a new prompt, and the model reported it. No tool errors.
| Model | Result | Requests / computer calls | Time |
|---|---|---|---|
anthropic:claude-sonnet-5-5 | pass | 4 / 3 | 34.9 s |
openai-responses:gpt-5.5 | pass | 4 / 3 | 36.9 s |
The display contract at 1024x768 also passed live; first use took 25.6 s, including the install. alpine:3.20 raised WorkspaceUnavailableError naming the missing programs and that there's no apt-get. Debian with allow_internet_access=False failed fast with WorkspaceUnavailableError from the install. All sandboxes were deleted afterwards, and the server was stopped.
Changes in this round
- The display is built with the shared
x11_display()from #11040, andDISPLAYis set in one line. - The test that a display which fails to start names the sandbox is cut: the message is the shared code's, and the E2B tests and
test_x11.pycover it. - The test fake routes display commands with the shared
FakeDisplay.answersinstead of its own program list. test_opensandbox_desktop.py7 passed,test_backend.py62.
Review rounds
Five rounds of gpt-6.2-sol (high effort) on the diff against the shared desktop code.
- Round 1:
desktopwas missing from the spec options sentence, and the skill line said execd 1.2 was required. Both fixed. - Round 2: the skill's install list was missing
util-linux. Added. - Round 3: the server's Docker runtime defaults to
network_mode = "host"(opensandbox_server/config.py). That shares the host's abstract X socket namespace, so a host X server on:1that accepts local clients could be driven. The docs now say to setbridge. They also say the install needs package access, and that a prepared backend needsdesktop=Truetoo. - Round 4: the Docker runtime's default
no_new_privileges = trueblockssudo, so the docs now say the install works as root. - Round 5: wording only, logged.
Also from the rounds:
- The desktop tests now skip off POSIX, like the other fake-server tests.
- Logged as shared desktop follow-ups: a first display call under Trio binds the display's lock before Trio is refused; filesystem reads start the display; a display whose Xvfb died isn't restarted.
The shared start script (#11040) now refuses when /proc/net/unix shows another @/tmp/.X11-unix/X1, since our Xvfb runs with -nolisten local. So on the default network_mode = "host", a host X server on :1 stops the desktop start instead of being driven.
Known limits
- The agent can type only ASCII, as with every X11 desktop.
- The desktop has no browser unless the image has one. A browser in the image when the desktop first starts gets a panel button.
- Installing on first use needs
apt-get, so a non-Debian image must have the programs already.