Add `desktop` to `ModalSandbox` for `ComputerUse`
- Part of #9347
Why
ComputerUse needs a screen. The shared X11 desktop that DockerContainer(desktop=True) and E2BSandbox(desktop=True) use runs unchanged on a Modal sandbox, so this PR adds the same desktop option to ModalSandbox.
The wiring uses the private x11_display() builder in _x11.py from #11040, as every other Xvfb desktop backend does.
Changes in this round
- The display is built with the shared
x11_display(), andDISPLAYis set in one line. _recheck_setsid, thestarted=hook and its mock test are cut. On real Modal sandboxes, every apt image checked (Modal's default,debian:bookworm-slim,debian:trixie-slim,ubuntu:24.04,ubuntu:26.04,python:3.13-slim,python:3.12-slim) hassetsidfromutil-linux, an essential package, so the display's start never installs it.- Renamed for clarity, following #11040:
checked_desktop_size,_display_operation,_mark_display_stopped. test_backend.py167 passed,test_modal_desktop.py6,test_modal_sandbox.py88.
New public surface
ModalSandbox.desktopandModalSandboxBackend(desktop=...):Truefor 1280x800, or(width, height). The default isFalse. Specs can set it.ModalSandboxBackend.display.
User-visible behavior
agent = Agent('anthropic:claude-opus-5-5', capabilities=[ModalSandbox(desktop=True), Coder(), ComputerUse()])
The display starts on first use. As on E2B, run() starts it before each shell command and adds DISPLAY, so programs the agent starts from the shell open on it. The display's own commands go through a new _run_argv, which doesn't start it.
Without an image, the default image adds the screen's programs (xvfb xdotool scrot x11-utils) and the desktop's (fluxbox tint2 xterm). A custom image gets them installed on first use (#11040). Live, image='python:3.12-slim' with desktop=(1024, 768) installed them in 27.9 s and passed the display contract at 1024x768. The computer tool counts as using the sandbox, so a desktop with only ComputerUse() doesn't warn that no tool uses it.
There's no live viewer; the docs show how to save each screenshot to watch a run. The agent can type only ASCII, as on the other X11 desktops.
Verification
-
modal_sandbox/test_modal_desktop.py: an agent runs the computer tool on a new sandbox; the default image has the display programs; a shell command finds the desktop running; a desktop size reaches the display; a reattached sandbox keeps its display. -
test_modal_live.py::test_a_desktop_meets_the_display_contractchecks the display contract against a real sandbox. -
test_modal_live.py::test_a_desktop_meets_the_display_contract: 1 passed live, 10.1 s. -
Live, with
ComputerUseand the sandbox only, no shell (2026-11-20). Task P is "latest Python on python.org", task E is "title of example.com". Modal's default image has no browser, so its panel has only the Terminal button:Sonnet P Sonnet E GPT P GPT E How 9 requests 6 9 15 All 4 went through the terminal: curl, python and apt-get install lynx. All correct.
All sandboxes were deleted afterwards.
What changes for existing users
Nothing: desktop defaults to False.
Review rounds
Two rounds with gpt-6.2-sol on this PR's own diff.
- Round 1: fixed two findings.
run()now checks the command before starting the display, so a string command withoutshell=Trueno longer creates a billable sandbox before itsTypeError. The live display-contract test now passes pyright. Not changed: a userenv={'DISPLAY': ...}override (as on E2B), and file operations needing a working desktop (as on Docker and E2B). - Round 2: clean.
Depends on
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.