Skip to content

Desktop and computer use

A sandbox from the desktop template runs an Xfce desktop. sandbox.desktop takes screenshots, moves and clicks the mouse, types, presses keys, launches applications, and mints a noVNC URL for watching live.

from svm import Sandbox
with Sandbox.create(template="desktop") as sandbox:
desktop = sandbox.desktop
seconds = desktop.wait_until_ready()
print(f"desktop ready after {seconds:.1f} s")
with open("desktop.png", "wb") as f:
f.write(desktop.screenshot())
desktop.move_mouse(400, 300)
desktop.left_click()
desktop.write("hello from SVM")
desktop.press("enter")
# A one-time noVNC link to watch the desktop live; treat it as a secret.
print(desktop.stream_url())
Method What it does
screenshot() PNG bytes. Waits for the first real frame after the desktop starts.
left_click(x, y), right_click, double_click, middle_click, drag Mouse
move_mouse(x, y), scroll(amount), get_cursor_position(), get_screen_size() Pointer and screen
write(text), press(key) Keyboard. Keys are X11 names or combinations.
launch(app, uri), open(path_or_url) Start an application
wait_and_verify(cmd, check) Poll until a condition holds, such as a window appearing
stream_url() A one-time noVNC URL