Add `DaytonaSandbox(desktop=True)` for computer use

Merged
AD
11d ago
+1366-16

Part of #9347

This PR adds DaytonaSandbox(desktop=True). It is a Daytona cloud sandbox with a desktop that ComputerUse() (#11037) can see and control. Daytona ships its own computer use API, so this PR drives the desktop through that API, not through our X11 driver. Most of the PR translates actions into that API's calls. The rest handles what the API can't do or doesn't confirm.

agent = Agent('anthropic:claude-sonnet-5-5', capabilities=[DaytonaSandbox(desktop=True), ComputerUse()])

How to review:

  1. Read the docstring at the top of daytona_sandbox/_desktop.py. It lists how Daytona's desktop behaves, as measured live. The translation follows from that list.
  2. Then read _send_input in the same file.
  3. Then read _display_operation in daytona_sandbox/_backend.py.

Changes in this round

  • Renamed for clarity, following the shared desktop code in #11040: DaytonaDisplayDriver, _MAX_CHARS_PER_CALL, _MAX_SCROLL_CLICKS_PER_CALL, _UNSUPPORTED_KEYS, _SUPPORTED_BUTTONS, _UNSHIFTED_KEY_FOR_SYMBOL, _release_after_failure, _display_operation, _mark_display_stopped and others.
  • A typing request times out after 60 s instead of 120 s. 2,000 characters take about 11 s.
  • Held input is released under the shared 5 s RELEASE_TIMEOUT in _display.py, as on the other desktops.
  • Drags end 1 pixel past the end point and back, and the press pause is gone, as in #11040.
  • test_daytona_desktop.py: 64 passed; _desktop.py at 100% branch coverage.

What the PR adds

  • Options. desktop=True gives a 1280x800 screen. For another size, pass desktop=(width, height). It works on DaytonaSandbox and on its backend. The size is set when the sandbox is created.
  • The desktop.
    • It runs on Daytona's default snapshot, which has XFCE, a terminal and Chromium.
    • The desktop start adds --no-sandbox to Chromium where its own sandbox can't work, so the dock's Web Browser button opens it.
    • It starts on first use or before the first shell command, whichever comes first. It starts again after a failure, or after the sandbox restarted.
    • Shell commands get DISPLAY=:0, so programs the agent starts open on the desktop.
  • Long input. Long text is typed 2,000 characters per request. Long scrolls go 500 wheel clicks per request.
  • Refused with UnsupportedActionError before anything is sent:
    • print screen, pause, scroll lock and the menu key, because Daytona refuses them with an error that doesn't prove nothing was pressed;
    • characters beyond U+FFFF, such as most emoji, because Daytona would drop them without an error.
  • Shifted symbols such as ! are pressed as shift plus the key they're on, because Daytona's key press refuses them.
  • Who can reach the desktop. Its VNC server has no password. On a private sandbox, anyone with a preview token for its port can see and control it. On a public sandbox, anyone with the preview URL can. The docs and THREAT_MODEL.md say so.
  • LazyDisplay (from #11040) is used with:
    • operation, which wraps every call so Daytona's errors become the harness's errors;
    • mark_stopped(), called when the backend closes, because the sandbox may stop before it is attached again.

Design decisions

Use Daytona's computer use API, not our X11 driver. Daytona's snapshot already has it, so nothing is installed. The cost is that Daytona's limits differ from Docker's and E2B's. The docs list them.

Input with an unknown outcome ends the run. Daytona keeps running a request it accepted, even when the caller stops waiting for it. So these errors all end the run with WorkspaceUnavailableError (c8599267b6, db84e892ff):

  • a timeout, including a 504;
  • a dropped connection;
  • a 502 from Daytona's proxy, which can come after the proxy has passed the input on.

The alternative was to let the model continue. But its next input could reach the screen at the same time as the old one. A clear refusal from Daytona is still a normal failed action.

A public sandbox gets a desktop too. Daytona's VNC preview of the desktop has no password, and a public sandbox's previews need no token, so anyone with the preview URL can control the desktop. Making a sandbox public is the user's choice, and it already exposes every preview port, so the SDK doesn't forbid it. The docs say plainly who can see and control the desktop in each case.

Refuse what Daytona can't press before sending it. Treat anything sent as possibly held. An earlier version let Daytona refuse side buttons and some keys itself. Then the code had to guess what was still pressed. A refused MouseDown('back') was still reported as "may still be held". A key-down that got a generic 500 was left out of cleanup, though the key may have gone down. Now there is one rule (cd7ac2388e):

  • Input Daytona can't do is refused before it is sent. A live probe of 71 key names found 10 that Daytona refuses. Daytona also refuses the side buttons, with "expected one of left, right, middle". Core already treats a refusal before sending as nothing pressed.
  • Anything sent counts as possibly held until its release is confirmed, whatever error came back. Cleanup then tries to release it.

Tests: test_what_daytona_cannot_do_is_refused_before_anything_runs, test_a_key_whose_hold_failed_is_let_go.

Start the desktop before each shell command, as on Docker (#11040). So a program the agent starts from the shell always has a screen. The desktop starts through Daytona's API, not inside the command (080c3bc336, test_a_shell_command_finds_the_desktop_running).

Let the snapshot's own Chromium start, instead of installing a browser. Daytona's snapshot already has Chromium behind the dock's globe. It only failed because Chromium's own sandbox can't run there. Adding --no-sandbox in /etc/chromium.d fixes the launcher the model already sees, and installs nothing. The flag is added only as root or where unshare -Ur true fails. It turns off the browser's own sandbox, which keeps a page that breaks into the browser away from the rest of the sandbox. The docs say so.

Any desktop size. An earlier version refused sizes below 1024x768. A live run showed that an 800x600 desktop keeps its size, so the refusal was dropped (dcb30deb36).

A desktop server error fails only that call. The next call starts the desktop again. The exception is a broken desktop that answers 503. That ends the run, because only stopping and starting the sandbox brings the desktop back.

Drags move in steps with short pauses and end 1 pixel past the end and back, through the shared drag_steps in #11040.

Evidence

All measured live on Daytona:

MeasurementResultUsed for
Typing 2,000 characters in one requestAbout 11 s2,000 characters per request
Scrolling 1,000 wheel clicks in one requestAbout 21 s, against a 30 s request limit500 clicks per request
A desktop created at 800x600Stays 800x600Dropping the smallest size
Pressing 71 key names, and the side buttonsDaytona refused 10 keys and the side buttonsRefusing them before sending
Input sent after a sandbox restart, before start()Breaks the desktop until the sandbox restartsChecking the desktop's status before starting it
The dock's globe before the Chromium fix"Failed to execute default Web Browser. Input/output error."Adding --no-sandbox
The dock's globe after the fix, fresh sandbox at a08cf74a56Chromium opens
network_block_all=True on a restricted-tier orgEvery host fails, including package registries, GitHub and AI APIsNot used here: the docs keep Daytona's tier caveat until a separate PR pins this with a live test

Browser runs after the Chromium fix (Sonnet 5.5 and GPT-5.5, ComputerUse only, no shell, a fresh sandbox each time):

OrgTaskWhat happenedRequestsResult
Full accessLatest Python on python.org (Sonnet)Clicked the dock's globe at step 2. Chromium opened python.org fully styled.6"Python 3.15.2"
Restricted tiergithub.com/pydantic/pydantic-ai description (Sonnet)Clicked the globe at step 2. github.com loaded without CSS or images, since GitHub's asset CDN isn't on Daytona's list.4The right description
Restricted tierpython.org and example.com (Sonnet and GPT, 4 runs)Clicked the globe at step 2 and Chromium opened. The sites reset the connection.5 to 17Both Sonnet runs reported the block plainly

Live tests (tests/harness/daytona_sandbox/test_daytona_live.py):

BehaviourTest
The display contracttest_display_contract
Commands see the desktoptest_commands_see_the_desktop
Modifier keys held around clicks and scrollstest_modifiers_are_held_around_clicks_and_scrolls
Keys and text reach the focused windowtest_keys_and_text_reach_the_focused_window
A small desktop keeps its sizetest_a_new_desktop_sandbox_below_1024x768_gets_that_size

Unit tests for the Chromium flag: test_the_desktop_start_lets_chromium_start, test_chromium_gets_no_sandbox_only_where_its_sandbox_cannot_work.

Known limits and follow-ups

  • There is no live viewer. To watch a run, save each screenshot as it arrives.
  • On Daytona's Tier 1 and Tier 2, a sandbox can reach only package registries, GitHub and AI APIs, even with allow_internet_access=True. So its browser can't open other sites. The tier can't be detected up front, because an API key can't read the org endpoint (401). The browser shows ERR_CONNECTION_RESET, which models report plainly.
  • If a run is cancelled while several held keys are being released, a key can stay held without any error.
  • A program started with cmd & inside run_command stops when that command ends, because Daytona ends the command's session. The model isn't told. start_command keeps a program running.

Testing

  • Unit tests over a fake Daytona SDK.
  • Live tests as above, plus the workspace and display conformance suites on a desktop sandbox.

Merging

This PR builds on #11040 (LazyDisplay and the drag steps).