Skip to content

Desktop

Computer-use controls for desktop sandboxes: screenshots, mouse, keyboard, windows and streaming.

Every method shows the same operation in each SDK; pick a language once and every tab on the site follows it.

Python TypeScript Go: Desktop Ruby: Desktop Java: Desktop

Computer-use controls for a running desktop sandbox.

Python exposes these as methods; see below.

Not in the Python SDK’s DesktopClient.

Not in the Python SDK’s DesktopClient.

Not in the Python SDK’s DesktopClient.

Not in the Python SDK’s DesktopClient.

def double_click(self, x: int | None=None, y: int | None=None) -> None
Parameter Type Default
x int | None None
y int | None None
Source: sdk/python/svm/desktop.py:144
def drag(self, start: tuple[int, int], end: tuple[int, int], steps: int=12) -> None
from DesktopExtras

Press at start, move to end through steps intermediate pointer positions and release.

A window manager starts moving a window only once it sees motion while the button is down, so a single jump from the press point to the release point (what four separate xdotool calls gave) does nothing. The whole gesture is one xdotool command, so the pointer events arrive back to back with a short pause between them.

Parameter Type Default
start tuple[int, int]
end tuple[int, int]
steps int 12
Source: sdk/python/svm/desktop_extras.py:65
def get_application_windows(self, application: str) -> list[str]
from DesktopExtras

Ids of the visible windows whose class or name matches application.

Parameter Type Default
application str

Returns list[str]

Source: sdk/python/svm/desktop_extras.py:136
def get_current_window_id(self) -> str
from DesktopExtras

Returns str

Source: sdk/python/svm/desktop_extras.py:133
def get_cursor_position(self) -> tuple[int, int]
from DesktopExtras

Returns tuple[int, int]

Source: sdk/python/svm/desktop_extras.py:113
def get_screen_size(self) -> tuple[int, int]
from DesktopExtras

Returns tuple[int, int]

Source: sdk/python/svm/desktop_extras.py:117
def get_window_title(self, window_id: str) -> str
from DesktopExtras
Parameter Type Default
window_id str

Returns str

Source: sdk/python/svm/desktop_extras.py:141
def has_app(self, application: str) -> bool

Whether the image has a desktop entry or a program named application. launch starts the app in the background and returns before it runs, so a missing app is not reported there: check with this first when the image is not known.

Parameter Type Default
application str

Returns bool

Source: sdk/python/svm/desktop.py:176

Not in the Python SDK’s DesktopClient.

def launch(self, application: str, uri: str | None=None) -> None

Start a desktop entry (firefox-esr, xfce4-terminal) or a program by name, in the background: this returns before the app runs and does not report one the image lacks (has_app checks that).

Parameter Type Default
application str
uri str | None None
Source: sdk/python/svm/desktop.py:187
def left_click(self, x: int | None=None, y: int | None=None) -> None
Parameter Type Default
x int | None None
y int | None None
Source: sdk/python/svm/desktop.py:130
def middle_click(self, x: int | None=None, y: int | None=None) -> None
from DesktopExtras
Parameter Type Default
x int | None None
y int | None None
Source: sdk/python/svm/desktop_extras.py:54
def mouse_press(self, button: str='left') -> None
from DesktopExtras
Parameter Type Default
button str 'left'
Source: sdk/python/svm/desktop_extras.py:59
def mouse_release(self, button: str='left') -> None
from DesktopExtras
Parameter Type Default
button str 'left'
Source: sdk/python/svm/desktop_extras.py:62
def move_mouse(self, x: int, y: int) -> None
Parameter Type Default
x int
y int
Source: sdk/python/svm/desktop.py:127
def open(self, file_or_url: str) -> None
from DesktopExtras

Open a file or URL with the desktop’s default handler.

Parameter Type Default
file_or_url str

Raises DesktopCommandError

Source: sdk/python/svm/desktop_extras.py:121
def press(self, key: str) -> None

Press a key or combination: an X11 keysym (Return, ctrl+c) or a common name (enter, esc, cmd+a). An unknown key raises instead of doing nothing (xdotool ignores it and still exits 0).

Parameter Type Default
key str
Source: sdk/python/svm/desktop.py:166
def right_click(self, x: int | None=None, y: int | None=None) -> None
Parameter Type Default
x int | None None
y int | None None
Source: sdk/python/svm/desktop.py:137

Not in the Python SDK’s DesktopClient.

def screenshot(self, *, wait_for_frame: float | None=FIRST_FRAME_WAIT_SECONDS) -> bytes

Capture PNG bytes.

Right after the sandbox starts the screen is black until the desktop session paints. Until this sandbox has shown a frame that is not one flat colour, a flat frame is captured again (every 100 ms, up to wait_for_frame seconds, default 5; 0 or None takes one capture) so the caller gets the first real frame instead of a black one; a capture that fails outright in that time (the display is not up yet) is tried again the same way. After the first real frame a flat frame (a black application, a screen saver) is returned as it is, at once, and a failed capture raises. If nothing was drawn within the wait the flat frame is returned, not an error; if every capture failed, the last failure is raised.

Parameter Type Default
wait_for_frame float | None FIRST_FRAME_WAIT_SECONDS

Returns bytes

Source: sdk/python/svm/desktop.py:93
def scroll(self, amount: int=1) -> None
Parameter Type Default
amount int 1
Source: sdk/python/svm/desktop.py:151

Not in the Python SDK’s DesktopClient.

def stream_url(self) -> str

Mint a one-time, short-lived noVNC browser entry URL; treat it as a secret. The noVNC server starts a few seconds after the sandbox runs, so this waits (up to 15 s) until it listens: a link minted earlier opens a 502 and is spent.

Returns str

Source: sdk/python/svm/desktop.py:224
def wait(self, ms: int) -> None
from DesktopExtras
Parameter Type Default
ms int
Source: sdk/python/svm/desktop_extras.py:89
def wait_and_verify(self, command: str, on_result: Callable[[Any], bool], *, timeout: float=10.0, interval: float=0.5) -> bool
from DesktopExtras

Run command in the desktop’s session every interval seconds until on_result accepts its result (True), or timeout seconds pass (False). on_result gets the command’s result (stdout, stderr, exit_code) whatever its exit code, so it can wait for a window to appear or a process to exit. The command runs at least once.

Parameter Type Default
command str
on_result Callable[[Any], bool]
timeout float 10.0
interval float 0.5

Returns bool

Source: sdk/python/svm/desktop_extras.py:97

Not in the Python SDK’s DesktopClient.

def wait_until_ready(self, timeout: float=60.0) -> float

Wait until the desktop session has painted (the first frame that is not one flat colour) and return the seconds it took.

A desktop sandbox reports running well before its session draws (about 17 s on the lab); until then every screenshot is black and clicks land on nothing. Call this once after create instead of looping on screenshot. Raises TimeoutError.

Parameter Type Default
timeout float 60.0

Returns float

Raises TimeoutError

Source: sdk/python/svm/desktop.py:199

Not in the Python SDK’s DesktopClient.

def write(self, text: str, *, chunk_size: int=25, delay_in_ms: int=75) -> None

Type in bounded chunks so a long string never overruns the input queue.

Parameter Type Default
text str
chunk_size int 25
delay_in_ms int 75
Source: sdk/python/svm/desktop.py:156

Not in the Python SDK’s DesktopClient.

Python TypeScript Go Ruby Java
def double_click(self, x=None, y=None)
Parameter Type Default
x None
y None
Source: sdk/python/svm/desktop_windows.py:61
def drag(self, start, end)
Parameter Type Default
start
end
Source: sdk/python/svm/desktop_windows.py:66
def get_application_windows(self, application)
Parameter Type Default
application
Source: sdk/python/svm/desktop_windows.py:110
def get_current_window_id(self)
Source: sdk/python/svm/desktop_windows.py:109
def get_cursor_position(self)
Source: sdk/python/svm/desktop_windows.py:107
def get_screen_size(self)
Source: sdk/python/svm/desktop_windows.py:108
def get_window_title(self, window_id)
Parameter Type Default
window_id
Source: sdk/python/svm/desktop_windows.py:111
def has_app(self, application: str) -> bool

Whether application resolves to a program on the guest’s PATH, the way launch starts it.

Parameter Type Default
application str

Returns bool

Source: sdk/python/svm/desktop_windows.py:82
def launch(self, application, uri=None)
Parameter Type Default
application
uri None
Source: sdk/python/svm/desktop_windows.py:80
def left_click(self, x=None, y=None)
Parameter Type Default
x None
y None
Source: sdk/python/svm/desktop_windows.py:59
def middle_click(self, x=None, y=None)
Parameter Type Default
x None
y None
Source: sdk/python/svm/desktop_windows.py:62
def mouse_press(self, button='left')
Parameter Type Default
button 'left'
Source: sdk/python/svm/desktop_windows.py:63
def mouse_release(self, button='left')
Parameter Type Default
button 'left'
Source: sdk/python/svm/desktop_windows.py:64
def move_mouse(self, x: int, y: int) -> None
Parameter Type Default
x int
y int
Source: sdk/python/svm/desktop_windows.py:53
def open(self, file_or_url)
Parameter Type Default
file_or_url
Source: sdk/python/svm/desktop_windows.py:106
def press(self, key)
Parameter Type Default
key
Source: sdk/python/svm/desktop_windows.py:79
def right_click(self, x=None, y=None)
Parameter Type Default
x None
y None
Source: sdk/python/svm/desktop_windows.py:60
def screenshot(self, *, wait_for_frame: float | None=None) -> bytes
Parameter Type Default
wait_for_frame float | None None

Returns bytes

Source: sdk/python/svm/desktop_windows.py:41
def scroll(self, amount=1)
Parameter Type Default
amount 1
Source: sdk/python/svm/desktop_windows.py:72
def stream_url(self) -> str
from DesktopClient

Mint a one-time, short-lived noVNC browser entry URL; treat it as a secret. The noVNC server starts a few seconds after the sandbox runs, so this waits (up to 15 s) until it listens: a link minted earlier opens a 502 and is spent.

Returns str

Source: sdk/python/svm/desktop.py:224
def wait(self, ms: int) -> None
from DesktopExtras
Parameter Type Default
ms int
Source: sdk/python/svm/desktop_extras.py:89
def wait_and_verify(self, command: str, on_result: Callable[[Any], bool], *, timeout: float=10.0, interval: float=0.5) -> bool
from DesktopExtras

Run command in the desktop’s session every interval seconds until on_result accepts its result (True), or timeout seconds pass (False). on_result gets the command’s result (stdout, stderr, exit_code) whatever its exit code, so it can wait for a window to appear or a process to exit. The command runs at least once.

Parameter Type Default
command str
on_result Callable[[Any], bool]
timeout float 10.0
interval float 0.5

Returns bool

Source: sdk/python/svm/desktop_extras.py:97
def wait_until_ready(self, timeout: float=60.0) -> float

Wait until the interactive session answers the helper and has drawn a frame that is not one flat colour; return the seconds it took. Raises TimeoutError.

Parameter Type Default
timeout float 60.0

Returns float

Raises TimeoutError

Source: sdk/python/svm/desktop_windows.py:91
def write(self, text, *, chunk_size=25, delay_in_ms=75)
Parameter Type Default
text
chunk_size 25
delay_in_ms 75
Source: sdk/python/svm/desktop_windows.py:74
Python TypeScript Go Ruby Java

A command run in the desktop’s session exited non-zero. A SandboxError, and still a RuntimeError; a screenshot taken before the display is up fails this way, which DesktopClient.screenshot waits out. Defined here so the extras (windows, cursor, drag, open) raise the same type as the core controls; svm.desktop.DesktopCommandError is this class.

Python exposes these as methods; see below.

Not in the Python SDK’s DesktopCommandError.

Not in the Python SDK’s DesktopCommandError.