Skip to content

Computer Use (Desktop)

Computer use endpoints let you programmatically control a full Linux desktop running inside a sandbox.

The runtime is based on Ubuntu 22.04 with an XFCE4 desktop at 1440x900 resolution. Firefox ESR, Google Chrome, and VS Code are pre-installed.

For a full endpoint reference, see the Computer Use (Desktop) API.

To open the desktop in a browser, see VNC Access.

Query the current display name and resolution. Useful for calculating coordinates before sending mouse or screenshot commands.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.display_info())

Change the virtual display resolution. Width must be between 320 and 7680, height between 320 and 4320.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.resize_screen(width=1280, height=800))

Inspect all open windows on the desktop. Each window includes its position, size, class, title, and whether it is focused.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
for window in sandbox.desktop.windows():
print(f"{window.title} ({window.width}x{window.height}) focused={window.focused}")

Capture the entire screen. Supports png, jpg, or jpeg format via the format query parameter. JPEG quality can be set with quality (1—100).

from pathlib import Path
from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
screenshot = sandbox.desktop.screenshot(image_format="png")
Path("screen.png").write_bytes(screenshot)

Capture a specific region of the screen.

from pathlib import Path
from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
region = sandbox.desktop.screenshot_region(
x=0,
y=0,
width=800,
height=600,
image_format="jpg",
quality=85,
)
Path("region.jpg").write_bytes(region)
from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.pointer_position())

Move the cursor to absolute coordinates. Returns the new pointer position.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.move_pointer(x=320, y=240))

Click at the current pointer position or at optional x, y coordinates. The button field maps to X11 buttons: 1 (left, default), 2 (middle), 3 (right). Returns the pointer position after the click.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
sandbox.desktop.click(x=320, y=240, button=1)
sandbox.desktop.click(button=3)

Drag from one coordinate to another. Uses button 1 (left) by default.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(
sandbox.desktop.drag(
from_x=100,
from_y=200,
to_x=400,
to_y=200,
)
)

Scroll at the current pointer position. Direction must be up, down, left, or right. The amount field controls how many scroll steps to perform (1—100, defaults to 1).

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
sandbox.desktop.scroll(direction="down", amount=3)

Type a string of text as if entered from the keyboard. Supports up to 50,000 characters.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
sandbox.desktop.type_text(text="hello from Leap0")

Press a single key by its X11 keysym name (e.g. Return, Escape, Tab, BackSpace, space).

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
sandbox.desktop.press_key(key="Return")

Press a multi-key shortcut. Pass an array of keys that will be joined with + and sent as a single xdotool key combination (e.g. ["ctrl", "l"] becomes ctrl+l). Accepts 1—10 keys.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
sandbox.desktop.hotkey(keys=["ctrl", "l"])

Screen recordings are captured as MP4 files (H.264/libx264, yuv420p) using ffmpeg at 12 fps. Files are saved inside the sandbox at ~/.cache/leap0-recordings by default (configurable via the LEAP0_RECORDINGS_DIR environment variable). Only one recording can be active at a time.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.start_recording())
from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.stop_recording())

Get the state of the current or most recent recording.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.recording_status())
from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
for recording in sandbox.desktop.recordings():
print(f"{recording.id}: {recording.size_bytes} bytes")
from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.get_recording("<recording_id>"))

Returns the MP4 file as a binary download.

from pathlib import Path
from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
recording = sandbox.desktop.download_recording("<recording_id>")
Path("recording.mp4").write_bytes(recording)

Delete a saved recording. Active recordings cannot be deleted. Stop them first. Returns 204 No Content on success.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
sandbox.desktop.delete_recording("<recording_id>")

The template runs five processes: xvfb (virtual framebuffer), xfce4 (desktop session), x11vnc (VNC server), novnc (web-based VNC client via websockify), and control (the HTTP API server). The four managed processes (xvfb, xfce4, x11vnc, novnc) can be inspected and restarted through the endpoints below.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.process_status())

Subscribe to a live Server-Sent Events stream of process status. The server sends an event immediately on connect, whenever a process status changes (e.g. after a restart), and every 2 seconds as a heartbeat. Each event has the same payload as GET /api/status. The connection stays open until the client disconnects.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
for status in sandbox.desktop.status_stream():
print(status)
break

Inspect or restart individual processes. Replace {name} with xvfb, xfce4, x11vnc, or novnc.

from leap0 import DEFAULT_DESKTOP_TEMPLATE_NAME, Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
print(sandbox.desktop.get_process("x11vnc"))
print(sandbox.desktop.restart_process("xfce4"))
print(sandbox.desktop.process_logs("novnc"))