> ## Documentation Index
> Fetch the complete documentation index at: https://docs.archil.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Desktops

> Run a full Linux desktop in a sandbox, open it in your browser, and let computer-use agents drive it.

A sandbox can run a full Linux desktop: Ubuntu with an XFCE desktop and Firefox, served over VNC through noVNC. Open
it in your browser to work in it, share a link with a teammate, or let a computer-use agent click and type while you
watch.

Desktops are ordinary [persistent sandboxes](https://docs.archil.com/compute/sandboxes/introduction.md) started from the open-source
[`ghcr.io/archil-data/sandbox-desktop`](https://github.com/archil-data/sandbox-desktop) image, so pause and resume,
forks, mounted disks, and the firewall all work the same way.

## Create a desktop

```bash CLI theme={null}
npx archil sandbox create my-desk --desktop
npx archil sandbox desktop my-desk
```

```typescript TypeScript theme={null}
import { Archil } from "disk";

const client = new Archil();
const desk = await client.sandboxes.create({ name: "my-desk", desktop: true });
await desk.desktop.start();
```

`desktop: true` (`--desktop` in the CLI) starts from the desktop image with 2 vCPUs, 4 GiB of memory, the idle
timeout turned off, and a 4-hour session cap. Any of those you pass yourself take precedence. The idle timeout is off
because viewer traffic doesn't count as sandbox activity; without that, a desktop would pause partway through a session.

`archil sandbox desktop` resumes the sandbox if it's paused or stopped, starts the desktop, and opens it in your
browser. It runs until you press Ctrl-C.

## View a desktop

There are two ways to open a desktop. Both need the desktop's **viewer token**, which the sandbox generates. Anyone
who has the token and can reach the desktop's port can see and control the desktop.

### Privately, on your machine

By default, `archil sandbox desktop` serves the desktop on `127.0.0.1` through a tunnel. Port 6080 stays private: the
tunnel authenticates with a short-lived [port token](https://docs.archil.com/compute/sandboxes/introduction.md#hosting-network-services) that
renews itself, and it keeps the sandbox awake while it runs. From code, use `openDesktopTunnel` from `disk/tunnel`
(Node.js only):

```typescript theme={null}
import { openDesktopTunnel } from "disk/tunnel";

const viewer = await openDesktopTunnel(desk);
console.log(viewer.viewerUrl); // http://127.0.0.1:6080/vnc.html?...
await viewer.close();
```

### With a shared link

`--share` publishes the desktop on a public HTTPS hostname and prints a link that includes the viewer token.
`--unshare` removes the hostname, replaces the token so old links stop working, and disconnects everyone viewing.

```bash CLI theme={null}
npx archil sandbox desktop my-desk --share
npx archil sandbox desktop my-desk --unshare
```

```typescript TypeScript theme={null}
const link = await desk.desktop.share();
await desk.desktop.unshare();
```

> [!WARNING]
>
> Anyone with a shared link can see and control the desktop until you unshare it. Treat the link like a password.

## Drive a desktop from code

The TypeScript SDK can operate the desktop directly, which is what computer-use agents need. Each call runs one
command in the sandbox and takes well under a second.

```typescript theme={null}
const png = await desk.desktop.screenshot();          // Uint8Array (PNG)
const { width, height } = await desk.desktop.size();

await desk.desktop.launch(["firefox", "https://example.com"]);
await desk.desktop.click(640, 400);                   // { button: "right", double: true } also work
await desk.desktop.moveMouse(100, 200);
await desk.desktop.type("hello");
await desk.desktop.key("ctrl+l");                     // Return, ctrl+shift+t, alt+F4, ...
await desk.desktop.scroll("down", 5);
```

Use `launch` to start programs. Anything an `exec` command starts in the background ends when that command returns;
`launch` detaches the program so it keeps running on the desktop.

From other languages, run the same commands with `exec`: `desktopctl up` starts the desktop and prints its token, and
`xdotool` and `scrot` run against display `:1`.

## Forks

A fork copies its parent's disk, viewer token included. Rotate the fork's token before you share it:

```typescript theme={null}
const copy = await desk.fork({ name: "my-desk-copy" });
await copy.desktop.token({ rotate: true });
```

## Customize the image

Build on the published image to add your own software, then create desktops from it:

```dockerfile theme={null}
FROM ghcr.io/archil-data/sandbox-desktop:latest
RUN apt-get update && apt-get install -y --no-install-recommends gimp libreoffice-writer
```

```bash CLI theme={null}
npx archil sandbox create my-desk --desktop --base-image ghcr.io/acme/desktop:1
```

```typescript TypeScript theme={null}
const desk = await client.sandboxes.create({ desktop: true, baseImage: "ghcr.io/acme/desktop:1" });
```

For a private image, build it with the [images API](https://docs.archil.com/compute/sandboxes/images.md) and pass `imageId` with
`desktop: true`.

## Good to know

* The desktop runs as the unprivileged `desktop` user, who has passwordless `sudo`. The sandbox VM is the security
  boundary.
* The desktop comes back by itself after a stop and start, and a pause and resume keeps open windows intact.
* Desktops include `openssh-server`, so [SSH](https://docs.archil.com/compute/sandboxes/ssh-and-ports.md) works right away.
* A paused desktop costs only storage. Delete desktops you're finished with.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.