Cua Sandbox gives an agent a full, isolated computer it can both run code in and drive through the graphical interface. In this tutorial you create an ephemeral Linux sandbox on your local machine using Docker, run a command inside it, interact with the sandbox clipboard, and save a screenshot to disk. When the script exits, the sandbox destroys itself automatically — no cleanup required.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/trycua/cua/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites: Python 3.11 or later (3.12/3.13 recommended) and Docker Desktop or Docker Engine running on your machine.
Steps
Install the SDK
Open a terminal and install the Python SDK:This installs the
cua meta-package, which includes cua-sandbox, cua-agent, and cua-cli. If you only need the sandbox SDK (and want a wider Python version range), you can install cua-sandbox directly — it supports Python 3.11–3.13.Create the script
Create a file named
first_sandbox.py:first_sandbox.py
Image.linux(kind="container") selects a lightweight Linux desktop container as the sandbox’s starting environment. Passing local=True tells the SDK to use your local Docker daemon rather than the cloud backend.Run the script
Run the script from the same directory:You should see output like:A file named
screenshot.png will appear in your current directory showing the sandbox desktop.Understand what happened
Sandbox.ephemeral(..., local=True) created a Linux desktop container through Docker. The script ran uname -a inside that container, printed the output, changed and read the sandbox clipboard, took a screenshot of the virtual desktop, and wrote it to screenshot.png.When the async with block exited, the sandbox destroyed itself. Ephemeral sandboxes are temporary by design — they accumulate state only while they live, and leave nothing behind.What the sandbox gives you
The sandbox exposes two complementary halves of the same computer: The code half lets you run programs inside the sandbox:Sandbox images
AnImage is the immutable description of the sandbox’s starting environment. It defines the OS type, installed packages, environment variables, and setup commands. Multiple Image variants are available:
Ephemeral vs. persistent sandboxes
By default, sandboxes are ephemeral — they are destroyed when theasync with block exits. For work that needs to survive process restarts, you can create a named persistent sandbox:
persistent_sandbox.py
Next steps
How sandboxes work
Understand isolation, runtime backends, images, snapshots, forks, and lifecycle patterns.
Sandbox lifecycle
Learn how to create, connect, snapshot, fork, and delete sandboxes.
Choose a sandbox image
Pick and customize an
Image for your OS and workload.Sandbox SDK reference
Complete API reference for all sandbox methods and types.