@daytona/use-computer
v0.1.16
Published
TypeScript SDK for use.computer — rent dedicated macOS VMs built for computer-use agents.
Readme
@daytona/use-computer — TypeScript SDK
use.computer gives you macOS sandboxes: VMs on dedicated Apple M4 Mac minis that you reserve for 24 hours or more, up to 2 VMs at a time per Mac. Parity with the Python SDK; async-native.
npm install @daytona/use-computer
export USE_COMPUTER_API_KEY=uc_live_...Quickstart
Flow: sign up → $100 starter credit → reserve a Mac mini (dashboard, or client.reserve(hours=24) in the SDK) → create() a macOS sandbox → drive it (mouse, keyboard, screenshot, exec, files, recording, UI tree, VNC) → delete(). The gateway configures the hourly price for each Mac model; check the live dashboard before reserving. The starter credit pays for reservations, and each reservation keeps its purchase rate.
import { Computer } from "@daytona/use-computer";
const computer = new Computer(); // baseUrl + apiKey from env, or pass {baseUrl, apiKey}
// 1. Reserve one M4 Mac Mini for 24 hours
const reservation = await computer.reserve({ hours: 24, macModel: "m4" });
// 2. Launch a macOS sandbox on the reserved Mac
const mac = await computer.create({ reservationId: reservation.reservation_id });
try {
// 3. Drive the macOS sandbox
await mac.exec("open -a Safari");
await mac.keyboard.type("hello from use.computer");
await mac.mouse.click(500, 500);
const png = await mac.screenshot.takeFullScreen();
console.log("Sandbox:", mac.sandboxId);
console.log("Open this sandbox in the use.computer dashboard console.");
} finally {
await mac.close();
}Treat vncUrl as an account credential: never print it, paste it into support tickets, or include it in logs or process arguments. Open the viewer through the dashboard console.
Gateway URLs (including USE_COMPUTER_BASE_URL) must use HTTPS, except HTTP on loopback hosts (localhost, 127.0.0.0/8, or ::1). Authenticated requests reject redirects rather than forwarding credentials.
Reservation purchases, sandbox creates (including snapshot restores), and snapshots use a fresh idempotency key per logical call. Timeout/network failures and transient HTTP 500/502/503/504/529 responses retry up to three times, two seconds apart, with the same key and exact body. Other mutations are sent once, and redirects are never retried. Gateway deduplication is live for purchases; create, snapshot, and restore support is being added in mmini-sandbox#118.
Surface
Computer.reserve({ hours?, miniCount?, macModel?, vmLayout? })→ reserve one Mac Mini from account credits.macModelis"m4"(the default; 10 vCPU and 16 GiB RAM),"m4-pro"(12 vCPU and 24 GiB RAM), or"m5-pro"(15 vCPU and 24 GiB RAM); the response reportsreservation.mac_model.vmLayoutis deprecated and sent only when you pass it:"split"(the server default) allows two sandboxes, and"whole"allows one sandbox at a time.Computer.create({ reservationId?, host?, snapshot?, ephemeral?, cpu?, memoryGib?, diskGib? })→MacOSSandbox. Omittingephemeraluses the server default: the reservation lifetime. Explicittrueopts into destruction after 2 idle minutes; explicitfalsedisables idle destruction. Callsandbox.keepalive()during idle periods when opting in. Omittedcpu,memoryGib, anddiskGibselect an available warm VM and start right away. Split warm VMs have 5 vCPU/8 GiB on M4, 6 vCPU/12 GiB on M4 Pro, and either 8 vCPU/12 GiB or 7 vCPU/12 GiB on M5 Pro; whole warm VMs have 10 vCPU/16 GiB, 12 vCPU/24 GiB, and 15 vCPU/24 GiB respectively. The response reports the selected slot's actual CPU and memory. Any other size boots a new VM, which can take up to 5 minutes, so the create waits up to 10 minutes when you set any of them. A Mac runs at most 2 sandboxes at a time, and their sizes must fit in the Mac. The sandbox reportscpu,memoryGib,diskGib, andboot("warm"or"cold"). A refused size throwsSandboxResourcesErrorwithcode(invalid_resources,resources_exceed_mac,sandbox_limit_reached, orinsufficient_capacity),message, andstatus.Computer.platforms(reservationId?)→ discover available platforms and capacity. For Mac reservations,macos.capacityreportsmaxandusedmacOS VMs.Computer.snapshots()→ list saved macOS snapshot versions.MacOSSandbox:mouse.move(x, y),mouse.click(x, y, button?),mouse.doubleClick(x, y),mouse.scroll(x, y, direction, amount),mouse.drag(startX, startY, endX, endY, button?),mouse.position()keyboard.type(text),keyboard.press(key),keyboard.hotkey(keys)screenshot.takeFullScreen(),screenshot.takeCompressed()recording.start(),recording.stop(id),recording.listAll(),recording.download(id)permissions.allowAutomation({ bundleIds?, installed? })→{ success, targets, changed }exec(cmd)/execSsh(cmd)→ run command via SSHupload(bytes, path),download(path)uiTree()→ native UI treesnapshot(name)→ capture disk state to boot future sandboxes instantlykeepalive(),close(),delete()
Docs: docs.use.computer.
Install from source when publication is unavailable
The npm package lives in js/, not the repository root. Check out the full commit SHA containing the feature you need, then build and pack that subdirectory:
git clone https://github.com/daytona/use-computer-sdk.git
git -C use-computer-sdk checkout FULL_COMMIT_SHA
npm --prefix use-computer-sdk/js ci
npm --prefix use-computer-sdk/js run build
npm pack ./use-computer-sdk/js
npm install ./daytona-use-computer-0.1.0.tgzReplace the final filename with the tarball filename printed by npm pack (the checkout's package version determines it). Run the install command in your application directory with the corresponding tarball path. Do not install the repository root as an npm Git dependency: it has no root package. For reservation purchases without a newer SDK, see the REST fallback.
Native computer actions
mouse.click(x, y, "middle", 3) sends one native triple-click sequence.
mouse.down(button) and mouse.up(button) hold/release at the current cursor;
optional x/y move to that position first. keyboard.hold("shift", 0.5) holds
keys for seconds. mouse.drag([[x1, y1], [x2, y2], [x3, y3]]) preserves each
path point. Numeric mouse.scroll(x, y, dx, dy) sends both pixel deltas, positive
right/down. Coordinates are screenshot pixels; Control and Command are distinct.
Application automation permissions
macOS asks for consent when a process sends Apple events through AppleScript or
osascript. That dialog cannot be answered inside the sandbox. The gateway
approves every installed application when creating a sandbox or restoring a
snapshot. After installing another application, approve it before scripting it:
await mac.exec("brew install --cask google-chrome");
const result = await mac.permissions.allowAutomation({
bundleIds: ["com.google.Chrome"],
});
console.log(result.success, result.targets, result.changed);
await mac.exec(`osascript -e 'tell application "Google Chrome" to activate'`);Use { installed: true } to approve all currently installed applications, or
combine it with bundleIds to include specific targets. These permissions cover
osascript, SSH sessions, exec, and Terminal.
The method sends POST /v1/sandboxes/{sandboxID}/permissions/automation, mapping
bundleIds to bundle_ids. Supply bundle IDs, installed: true, or both.
The typed AllowAutomationResult contains success: boolean and integer counts
targets and changed; the request type is AllowAutomationOptions.
The gateway validates bundle IDs against ^[A-Za-z0-9][A-Za-z0-9._-]{0,254}$
and rejects malformed IDs or an empty request with HTTP 400 { error: ... },
surfaced as the standard UseComputerError. The SDK does not validate locally.
