basetenlabs/computer-use-sandbox-cookbook
Python
Captured source
source ↗basetenlabs/computer-use-sandbox-cookbook
Description: Computer-use agents on Baseten Sandboxes: a cloud Linux desktop with Chrome, a live view, and a vision-model agent loop
Language: Python
License: MIT
Stars: 0
Forks: 0
Open issues: 0
Created: 2026-11-25T20:59:06Z
Pushed: 2026-11-25T21:04:43Z
Default branch: main
Fork: no
Archived: no
README:
Computer-use agents on Baseten Sandboxes
Give each of your users their own computer in the cloud, and an AI agent that uses it the way a person does: it looks at the screen, moves the mouse, types, and drives a real Google Chrome. Your user watches live from their own browser and can take over at any point, for example to sign in. The computer keeps its windows, files and logins between tasks.

*Four users, four computers, four tasks at the same time. Each desktop is its own Baseten Sandbox.*
Using a coding agent? Point it at [AGENTS.md](AGENTS.md): setup, a --json mode with exit codes, and the checks to run.
Quickstart
You need Python 3.11 or later, uv, and a Baseten API key with access to Sandboxes and Model APIs.
git clone https://github.com/basetenlabs/computer-use-sandbox-cookbook cd computer-use-sandbox-cookbook uv sync export BASETEN_API_KEY=... uv run computer-use-image # once per team, about 2 minutes uv run computer-use "On Wikipedia, find the year the Golden Gate Bridge opened. Answer with just the year."
Opening desktop desktop-ada (about a minute the first time, seconds after)... Watch or take over: https:///vnc.html?autoconnect=true&reconnect=true&resize=scale&preview_token=... 1. browser_open(url='https://en.wikipedia.org/wiki/Golden_Gate_Bridge') 2. done(answer='1937') 1937 (2 steps, 8s, 5,488 input and 208 output tokens) The desktop stays up for reuse. Delete it with: computer-use --delete --desktop desktop-ada
Open the link to watch the agent work. Click into the desktop to take over. The first run creates your desktop, which takes about a minute. Running again with the same --desktop name reconnects in about 2 seconds.
Other options: --model, --no-browser-tools (screen, mouse and keyboard only), --max-turns, --image, --human-pace (see below), --delete (delete the desktop at the end, or right away when there is no task) and --json (only a JSON result on stdout, for scripts and coding agents; the exit code is 0 when the agent ended with an answer, 1 when it ran out of turns).
What's in this repo
A small, tested Python reference you can copy into your backend:
computer_use/desktop.py:Desktop, one user's computer (one Baseten
Sandbox). Screenshots, mouse, keyboard, the browser through Playwright, and a live view link.
computer_use/agent.py:run_task, the agent loop. Works with any
OpenAI-compatible vision model and defaults to Baseten Model APIs.
computer_use/image.py: the desktop image, and thecomputer-use-image
command that builds it once for your team.
tests/: end-to-end tests against real sandboxes and real models.AGENTS.md: instructions for coding agents.
How it works
flowchart TB model["Vision model on Baseten Model APIs"] loop["run_task: the agent loop (your backend)"] viewer["Your user's browser"] subgraph sandbox["Baseten Sandbox, one per user"] direction LR server["Computer server: screen, mouse, keyboard"] chrome["Google Chrome DevTools"] vnc["XFCE desktop over VNC, 1024x768"] end model loop loop -- "/port/8000" --> server loop -- "/port/9223" --> chrome viewer -- "live view link" --> vnc
The loop runs in your backend. Each turn it sends the model the task, the conversation so far and a fresh screenshot. The model answers with tool calls, the loop runs them on the desktop, and it repeats until the model calls done.
| Tool | What the model can do with it | | --- | --- | | computer | Click, double-click, right-click, move, drag, type, press keys (ctrl+l), scroll and wait, by pixel coordinates on the screenshot. | | browser_open, browser_snapshot, browser_click, browser_type, browser_select, browser_read | Act on web pages through element references from the page's accessibility tree. Faster and more reliable than pixels. | | ask_user | Ask the user for something only they can give: a sign-in, a one-time code, approval for a purchase. | | done | Finish with an answer for the user. |
The browser tools and the mouse drive the same Chrome window your user sees, so the agent can mix them, and your user can step in halfway through.
The sandbox runs computer-use-desktop, an image you build once with uv run computer-use-image (139 seconds the first time, seconds after). It starts from the same desktop as Baseten's built-in baseten/cua-xfce:latest image (Ubuntu 22.04 with an XFCE desktop, VNC, noVNC and a computer server) and adds Google Chrome, the Mousepad text editor, xdotool, and Chrome policies that turn off sign-in, sync, password saving and other prompts that would cover the page. It also takes away the desktop user's root access and stops web pages from reaching the sandbox's own services (see Security). Desktop.open starts Chrome with DevTools on.
The built-in image works too (--image baseten/cua-xfce:latest): Desktop.open then downloads Chrome on the desktop's first start, and the desktop has no application menu or icons, which makes desktop apps harder for the model to find. It also keeps the base image's defaults that Security describes, so use it only to try things out.
Use it from your backend
from computer_use import Desktop
from computer_use.agent import run_task
# One desktop per user. The same name reconnects to the same computer.
with Desktop.open(f"desktop-{user_id}") as desktop:
show_in_your_app(desktop.live_view_url()) # A link for your user.
result = run_task(
desktop,
"Find a table for two at 7pm on Friday near Union Square and book it.",
ask_user=ask_in_your_app, # Called when the agent needs your user; return their reply.
approve=check_in_your_app, # Called before every action; return False to block it.
on_step=stream_to_your_app, # Called after every action,...Excerpt shown — open the source for the full document.