Add `E2BSandbox(desktop=True)` for computer use
Part of #9347
This PR adds E2BSandbox(desktop=True). It is an E2B cloud sandbox with a desktop that ComputerUse() (#11037) can see and control. It uses the shared X11 driver and start script from #11040, so typing, drags and cleanup work the same as on Docker.
agent = Agent('anthropic:claude-sonnet-5-5', capabilities=[E2BSandbox(desktop=True), ComputerUse()])
How to review: read _START_DESKTOP and the __init__ wiring in e2b_sandbox/_backend.py. Everything else is the shared code in #11040.
What the PR adds
- Options.
desktop=Truegives a 1280x800 screen. For another size, passdesktop=(width, height). - The template. Without a
template, a new sandbox runs E2B'sdesktoptemplate: Ubuntu with XFCE, a terminal and Google Chrome. A custom template without the display's programs gets them installed on first use when it can, as described in #11040;startxfce4is needed for the XFCE desktop. - The display.
- It starts on first use, under the same lock as the X server, so starts at the same time share one desktop.
- It waits until XFCE's desktop window appears on this display, so the first screenshot isn't black. An XFCE session on another display doesn't count.
- The size applies when the display first starts. A sandbox that is attached again keeps its display's size.
- It also starts before each shell command, and shell commands get
DISPLAY, so a program the agent starts from the shell opens on the screen.
- Long input. Long typing and long drags are split into
xdotoolcommands of at most 100,000 bytes each (the split is in #11040). E2B runs a command as onebash -l -cargument, and Linux limits one argument to 131,072 bytes.
Design decisions
Share the X11 driver, not E2B's Desktop SDK. With one driver, Docker's fixes apply here too: ASCII-only typing, the drag steps, releasing keys and buttons on cancel, and the -noreset start. This backend starts its own X server on display :1.
sandbox_timeout stays the whole lifetime of the sandbox, as for E2B sandboxes without a desktop. The docs say to set it longer than the longest task.
Changes in this round
- The display is built with the shared
x11_display()andDISPLAYis set in one line, so E2B no longer re-checkssetsidafter a start: every apt image has it (util-linuxis an essential package). This also brings__init__back under the complexity limit. - Docs, README and skill: the Print key opens XFCE's screenshot dialog instead of reaching the app. The sentence about the Desktop SDK's other display is gone.
- Review thread on
test_x11.py: the test no longer patches a private byte limit. It types 20,000 characters and drags through 2,500 points, and checks every command stays under the limit. test_e2b_desktop.py12 passed,test_backend.py147 passed.
Evidence
Live probe on E2B's desktop template:
| Command | Result |
|---|---|
| A 130,630-byte command line | Started |
| A 130,664-byte command line | Refused: "argument list too long" |
| Typing 25,000 characters in one command | Failed |
Live tests (tests/harness/e2b_sandbox/test_e2b_live.py):
| Behaviour | Test |
|---|---|
| The template runs no X server until the display starts | test_the_template_runs_no_x_server_until_the_display_starts |
| The display contract | test_display_contract |
| The first screenshot isn't black | test_the_first_screenshot_shows_the_desktop |
| Typed text, including tab and newline, reaches a window | test_typed_text_reaches_the_focused_window |
An E2B desktop started its display through the shared install path in 9 s.
Unit tests (test_e2b_desktop.py) cover which template is used, the size, attaching again, XFCE starting unless its window is already there, XFCE exiting, a template without XFCE, and an X server outside the sandbox on :1. The start scripts run in a real shell.
No model run with only ComputerUse was repeated on E2B in this round.
Known limits and follow-ups
- There is no live viewer. To watch a run, save each screenshot as it arrives.
- The Print key opens XFCE's screenshot dialog instead of reaching the app. The docs say so.
- A screenshot whose base64 text is over 10 MiB goes past the backend's output limit. Only near-random pixels get that large.
Merging
This PR builds on #11040.
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.
Live check
On a real E2B sandbox (the desktop template), with ComputerUse and the sandbox only, no shell (2026-11-24). 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.
| Model | Result | Requests / computer calls | Time |
|---|---|---|---|
anthropic:claude-sonnet-5-5 | pass | 3 / 2 | 22.8 s |
openai-responses:gpt-5.5 | pass | 3 / 2 | 18.6 s |
The display contract at 1024x768 also passed live; the first screenshot isn't blank, and first use took 6.3 s.