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())import { writeFile } from "node:fs/promises";import { Sandbox } from "@svm/sandbox";
const sandbox = await Sandbox.create({ template: "desktop", wait: true });try { const desktop = sandbox.desktop; await desktop.waitUntilReady();
await writeFile("desktop.png", await desktop.screenshot()); await desktop.moveMouse(400, 300); await desktop.leftClick(); await desktop.write("hello from SVM");
console.log(await desktop.streamUrl()); // one-time, short-lived noVNC URL: treat it as a secret} finally { await sandbox.kill();}sandbox, err := client.CreateSandbox(ctx, svm.CreateSandboxOptions{Template: "desktop"})if err != nil { return err}defer sandbox.Kill(ctx)
desktop := sandbox.Desktop()if _, err := desktop.WaitUntilReady(ctx, 0); err != nil { // 0: up to 60 s for the first painted frame return err}png, err := desktop.Screenshot(ctx, 0)if err != nil { return err}if err := os.WriteFile("desktop.png", png, 0o644); err != nil { return err}
if err := desktop.MoveMouse(ctx, 200, 150); err != nil { return err}if err := desktop.LeftClick(ctx); err != nil { // at the pointer; LeftClick(ctx, x, y) moves first return err}if err := desktop.Write(ctx, "hello from the SDK"); err != nil { return err}
url, err := desktop.StreamURL(ctx) // one-time noVNC link: treat it as a secretif err != nil { return err}fmt.Println("watch at", url)require "svm"
box = SVM::Sandbox.create(template: "desktop")begin desktop = box.desktop seconds = desktop.wait_until_ready(timeout: 60) puts "desktop painted after #{seconds.round(1)} s"
File.binwrite("screen.png", desktop.screenshot) # PNG bytes
desktop.move_mouse(400, 300) desktop.left_click desktop.write("hello from SVM")
puts "watch live: #{desktop.stream_url}" # one-time URL; treat it as a secretensure box.killendimport dev.svm.sandbox.Client;import dev.svm.sandbox.Desktop;import dev.svm.sandbox.Sandbox;import java.nio.file.Files;import java.nio.file.Path;
public class DesktopExample { public static void main(String[] args) throws Exception { Client client = Client.fromEnvironment(); try (Sandbox sandbox = Sandbox.create(client, "desktop")) { Desktop desktop = sandbox.desktop(); desktop.waitUntilReady(); // up to 60 s for the display
Files.write(Path.of("desktop.png"), desktop.screenshot());
desktop.moveMouse(400, 300); desktop.leftClick(400, 300); desktop.write("hello from the SDK");
// A one-time noVNC URL to watch the desktop live; treat it as a secret. System.out.println(desktop.streamUrl()); } }}| 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 |