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

# Desktop

> A full Linux desktop with a browser, a terminal and VS Code, that a person watches in their own browser and an agent drives with screenshots, clicks and keys. For computer-use agents and apps that have no API.

Some work has no API. Think of an old admin panel, a desktop application, a website that blocks automation, or a
task you want a **computer-use model** to carry out the way a person would, by looking at the screen and clicking.
For that kind of work, a sandbox can have **a complete desktop**. It gives you:

* **A familiar desktop** with windows and a taskbar, a **browser**, a **terminal** and **VS Code**.
* **A link that a person opens in their own browser** to watch the desktop and take over when needed.
* **Screenshots, clicks and keystrokes** that your agent sends as ordinary commands.

Like everything else in a sandbox, **the desktop goes to sleep with its windows still open**, and wakes up exactly
as it was.

## Start a desktop

Ask for a desktop with `"needs": ["desktop"]` when you create the sandbox:

```bash title="CLI" run theme={null}
DESK=$(fibre create --needs desktop --lifetime 15m --label docs=desktop --json | jq -r .id)
fibre get "$DESK" --json | jq -r .runtime   # vm
```

```typescript title="TypeScript" run theme={null}
import { Sandbox } from "@fibre-dev/sdk";

const desk = await Sandbox.create({ needs: ["desktop"], lifetime: 900, labels: { docs: "desktop" } });
console.log(desk.runtime); // vm
```

```python title="Python" run theme={null}
from fibre import Sandbox

desk = Sandbox.create(needs=["desktop"], lifetime=900, labels={"docs": "desktop"})
print(desk.runtime)  # vm
```

```bash title="curl" run capture=SBX=.id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"needs": ["desktop"], "lifetime_sec": 900, "labels": {"docs": "desktop"}}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "id": "…",
>   "status": "running",
>   "runtime": "vm",
>   "runtime_reason": "needs:desktop",
>   "desktop_url": "…",
>   "desktop_expires_in": 300
> }
> ```

The call answers **once the desktop is up and ready**, and the answer includes a link to it. A desktop always uses
the `vm` runtime.

## Watch it, or hand it to a person

Open `desktop_url` in your browser. You see the sandbox's screen and can use it with your own mouse and keyboard,
as if you were sitting in front of it. Desktop links have a few safety rules:

* **Each link works once.** Whoever opens it first gets the desktop, and nobody else can reuse that link.
* **An unopened link expires** after `desktop_expires_in` seconds (300, so five minutes).
* **You can ask for a new link at any time**, for yourself or for a user who needs to step in:

```bash title="CLI" run theme={null}
fibre desktop "$DESK"   # https://… (works once; expires in 300 s if not opened)
```

```typescript title="TypeScript" run theme={null}
const link = await desk.desktop();
console.log(link.url, link.expiresIn); // https://… 300
```

```python title="Python" run theme={null}
link = desk.desktop()
print(link.url, link.expires_in)  # https://… 300
```

```bash title="curl" run theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$SBX/desktop" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" -d '{}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "url": "…",
>   "expires_in": 300
> }
> ```

> [!TIP]
>
> **Bring a person in when the agent needs help.** When your agent reaches a CAPTCHA, a two-factor login prompt, or
> a decision it should not make alone, send the user a fresh link. They deal with it on the same desktop, close the
> tab, and the agent carries on from there.

## Let an agent drive it

A computer-use agent works in a loop: **it looks at the screen, decides what to do, acts, and looks again.** On
Fibre, each of those steps is a single command run in the sandbox. The desktop's screen is display `:1`, which is
why the commands below start with `DISPLAY=:1`.

**1. Look: take a screenshot**

```bash title="CLI" run theme={null}
fibre exec "$DESK" -- 'DISPLAY=:1 scrot -o /tmp/screen.png'
fibre cp "$DESK:/tmp/screen.png" screen.png   # send it to your model
```

```typescript title="TypeScript" run theme={null}
await desk.run("DISPLAY=:1 scrot -o /tmp/screen.png");
const screen = await desk.files.readBytes("/tmp/screen.png");
console.log(`${screen.byteLength} bytes of PNG`); // send these to your model
```

```python title="Python" run theme={null}
desk.run("DISPLAY=:1 scrot -o /tmp/screen.png")
screen = desk.files.read_bytes("/tmp/screen.png")
print(f"{len(screen)} bytes of PNG")  # send these to your model
```

```bash title="curl" run theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$SBX/exec" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["sh", "-c", "DISPLAY=:1 scrot -o /tmp/screen.png && echo saved"]}'

curl -sS "$FIBRE_API_URL/v1/sandboxes/$SBX/files/content?path=/tmp/screen.png" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -o screen.png
file screen.png
```

> [accordion] Output
>
> ```text title="output" expected theme={null}
> PNG image data
> ```

**2. Act: click and type**

`xdotool` is a standard Linux tool that moves the mouse, clicks and types, exactly as a person would:

```bash title="CLI" run theme={null}
fibre exec "$DESK" -- "DISPLAY=:1 xdotool mousemove 640 400 click 1"   # click at x=640, y=400
fibre exec "$DESK" -- "DISPLAY=:1 xdotool type 'hello from an agent'"   # type text
fibre exec "$DESK" -- "DISPLAY=:1 xdotool key ctrl+l"                   # press keys
```

```typescript title="TypeScript" run theme={null}
await desk.run("DISPLAY=:1 xdotool mousemove 640 400 click 1");      // click at x=640, y=400
await desk.run("DISPLAY=:1 xdotool type 'hello from an agent'");     // type text
await desk.run("DISPLAY=:1 xdotool key ctrl+l");                     // press keys
```

```python title="Python" run theme={null}
desk.run("DISPLAY=:1 xdotool mousemove 640 400 click 1")  # click at x=640, y=400
desk.run("DISPLAY=:1 xdotool type 'hello from an agent'")  # type text
desk.run("DISPLAY=:1 xdotool key ctrl+l")  # press keys
```

```bash title="curl" run theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$SBX/exec" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["sh", "-c", "DISPLAY=:1 xdotool mousemove 640 400 click 1 && DISPLAY=:1 xdotool type \"hello from an agent\" && echo done"]}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "exit_code": 0,
>   "stdout": "done\n"
> }
> ```

**3. Put it in a loop with your model**

Now connect the two with a model. Each time round the loop, the model looks at the latest screenshot and replies
with the next action, and your code turns that action into a command. Here is a sketch of the loop, with the call
to your model left for you to fill in:

```typescript title="TypeScript" norun reason="needs a computer-use model and its API key" theme={null}
for (let step = 0; step < 30; step++) {
  await desk.run("DISPLAY=:1 scrot -o /tmp/screen.png");
  const screenshot = await desk.files.readBytes("/tmp/screen.png");

  const action = await askModel({ task: "Open the browser and find today's weather in Paris", screenshot });
  if (action.type === "done") break;

  if (action.type === "click") await desk.run(`DISPLAY=:1 xdotool mousemove ${action.x} ${action.y} click 1`);
  if (action.type === "type") await desk.run(`DISPLAY=:1 xdotool type ${JSON.stringify(action.text)}`);
  if (action.type === "key") await desk.run(`DISPLAY=:1 xdotool key ${action.keys}`);
}
```

```python title="Python" norun reason="needs a computer-use model and its API key" theme={null}
import shlex

for step in range(30):
    desk.run("DISPLAY=:1 scrot -o /tmp/screen.png")
    screenshot = desk.files.read_bytes("/tmp/screen.png")

    action = ask_model(task="Open the browser and find today's weather in Paris", screenshot=screenshot)
    if action["type"] == "done":
        break

    if action["type"] == "click":
        desk.run(f"DISPLAY=:1 xdotool mousemove {action['x']} {action['y']} click 1")
    if action["type"] == "type":
        desk.run(f"DISPLAY=:1 xdotool type {shlex.quote(action['text'])}")
    if action["type"] == "key":
        desk.run(f"DISPLAY=:1 xdotool key {action['keys']}")
```

## What is on the desktop

The desktop comes with these applications and tools:

| | |
| - | - |
| Desktop | A full Linux desktop with a taskbar and windows |
| Apps | Chromium, a terminal, a file manager, **VS Code** (in the browser) |
| Computer-use tools | `scrot` for screenshots, `xdotool` for mouse and keyboard |
| Screen | Display `:1` |

## Sleep

A desktop goes to sleep once **nobody is watching it** and nothing has been done through Fibre (no exec, command
or file call) for its idle timeout. Programs running on the desktop by themselves do not keep it awake. Opening a
new link, or making any call, wakes it **with the same windows, tabs and editor** as before.

## Clean up

```bash title="CLI" run theme={null}
fibre delete "$DESK"
rm -f screen.png
```

```typescript title="TypeScript" run theme={null}
await desk.delete();
```

```python title="Python" run theme={null}
desk.delete()
```

```bash title="curl" run theme={null}
curl -sS -X DELETE "$FIBRE_API_URL/v1/sandboxes/$SBX" -H "Authorization: Bearer $FIBRE_API_KEY"
rm -f screen.png
```

## Related

> [card] [Browser](https://docs.fibre.dev/connect/browser.md)
>
> If you only need a browser, it is lighter and faster.

> [card] [Runtimes](https://docs.fibre.dev/sandboxes/runtimes.md)
>
> Desktops run on the `vm` runtime. Find out what that means.


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