---
title: "How to set up a Linux desktop for an AI agent with Xvfb, a window manager and noVNC"
description: "A Linux desktop for an AI agent is five programs on one machine or container: a virtual display (Xvfb), a light window manager, an input tool such as xdotool, a screenshot tool, and optionally a VNC server with noVNC so a person can watch. Start them in that order, as a non-root user."
url: "https://www.vmforai.com/issue/linux-desktop-for-an-ai-agent/"
site: "VMForAI.com"
author: "VMForAI editors"
published: "2026-11-26"
updated: "2026-11-26"
---

# How to set up a Linux desktop for an AI agent with Xvfb, a window manager and noVNC

VMForAI editors. Published 2026-11-26, updated 2026-11-26.

A Linux desktop for an AI agent is five programs on one machine or container: a virtual display (Xvfb), a light window manager, an input tool such as xdotool, a screenshot tool, and optionally a VNC server with noVNC so a person can watch. Start them in that order, as a non-root user.

A Linux desktop for an AI agent is a virtual screen plus the few programs that make it behave like a normal computer. The agent never needs a monitor: it needs pixels to look at, a way to send mouse and keyboard events, and a window manager so applications open where they should.

## What are the parts of an agent desktop?

An agent desktop has five parts, each a separate open-source program.

Table: The parts of a Linux desktop for an agent

| Part | What it does | Common open-source choice |
|---|---|---|
| Virtual display | Holds the screen in memory and runs X applications | Xvfb |
| Window manager | Draws title bars, places and focuses windows | Openbox (or another light one) |
| Input | Sends mouse moves, clicks and key presses to the display | xdotool, or pyautogui from Python |
| Screenshot | Captures the screen as an image for the model | FFmpeg's x11grab device, or the agent framework's own capture |
| Viewer (optional) | Lets a person watch or take over in a browser | x11vnc with noVNC and websockify |

Xvfb's manual describes it as "an X server that can run on machines with no display hardware and no physical input devices" which "emulates a dumb framebuffer using virtual memory" ([Xvfb manual, Debian bookworm](https://manpages.debian.org/bookworm/xvfb/Xvfb.1.en.html), read 2026-11-26). Openbox describes itself as "a minimalistic, highly configurable, next generation window manager with extensive standards support" ([Openbox](https://openbox.org/), read 2026-11-26).

## Step 1: How do I start the virtual display?

Start Xvfb on a free display number with an explicit screen size and depth, and switch off TCP listening.

```
export DISPLAY=:99
Xvfb :99 -screen 0 1280x1024x24 -nolisten tcp &
```

`-screen 0 1280x1024x24` "creates screen screennum and sets its width, height, and depth" (Xvfb manual). Always set it: the default depth differs between documentation versions, as our [Xvfb setup guide](https://www.vmforai.com/issue/xvfb-virtual-display-setup/) shows. `-nolisten tcp` is the X server option that disables TCP/IP connections ([Xserver manual](https://xorg.freedesktop.org/archive/current/doc/man/man1/Xserver.1.xhtml), read 2026-11-26), so only programs on the same machine can draw on or read the screen.

Programs started too early fail with "cannot open display". Wait until the display answers before going on, for example by looping on `xdpyinfo`, a utility "for displaying information about an X server" ([xdpyinfo manual](https://manpages.debian.org/bookworm/x11-utils/xdpyinfo.1.en.html), read 2026-11-26).

## Step 2: Why start a window manager, and which one?

Start a window manager so that windows get focus, borders and sensible positions. Without one, new windows appear at the top-left corner with no title bar, and keyboard focus may not follow the window the agent clicked. Any light window manager works. Openbox is a common choice because it is small and needs no configuration to start:

```
openbox &
```

## Step 3: How does the agent send input and take screenshots?

The agent sends input with a tool that injects events into the X server and takes screenshots by reading the screen.

- **Input.** xdotool "does this using X11's XTEST extension and other Xlib functions" ([xdotool manual](https://manpages.debian.org/bookworm/xdotool/xdotool.1.en.html), read 2026-11-26). `xdotool mousemove 640 512 click 1` moves and left-clicks. See [mouse and keyboard input for agents](https://www.vmforai.com/issue/xdotool-mouse-and-keyboard-input-for-agents/).
- **Screenshots.** FFmpeg's x11grab device "allows one to capture a region of an X11 display" ([FFmpeg devices](https://ffmpeg.org/ffmpeg-devices.html), read 2026-11-26). One frame as a PNG: `ffmpeg -y -f x11grab -video_size 1280x1024 -i :99 -frames:v 1 shot.png`. The `-frames` option means "Stop writing to the stream after framecount frames" ([ffmpeg manual](https://ffmpeg.org/ffmpeg.html), read 2026-11-26).

## Step 4: How do I let a person watch?

Let a person watch by running a VNC server on the display and noVNC in front of it, both kept off public addresses.

```
mkdir -p ~/.vnc
x11vnc -storepasswd "$VNC_PASSWORD" ~/.vnc/passwd
x11vnc -display :99 -localhost -rfbport 5900 -rfbauth ~/.vnc/passwd -forever -shared &
VNC_HOST=localhost
websockify --web /usr/share/novnc 6080 "${VNC_HOST}:5900" &
```

`-localhost` restricts x11vnc to connections from the same machine, and websockify "translates WebSockets traffic to normal socket traffic" so a browser can reach it ([websockify](https://github.com/novnc/websockify), read 2026-11-26). The details, including view-only mode, are in [watching an agent desktop with VNC and noVNC](https://www.vmforai.com/issue/watch-an-agent-desktop-with-vnc-and-novnc/).

## What does a complete example look like?

The example below puts the four steps in one container image. It is an example to adapt, not a hardened image. The package names are Debian's: the `novnc` package installs the web client under `/usr/share/novnc` ([novnc file list](https://packages.debian.org/bookworm/all/novnc/filelist), read 2026-11-26) and `python3-websockify` installs the `websockify` command ([python3-websockify file list](https://packages.debian.org/bookworm/all/python3-websockify/filelist), read 2026-11-26).

The start script, `start-desktop.sh`:

```
#!/bin/bash
set -euo pipefail
export DISPLAY=:99
Xvfb :99 -screen 0 1280x1024x24 -nolisten tcp &
for _ in $(seq 1 50); do xdpyinfo >/dev/null 2>&1 && break; sleep 0.1; done
openbox &
mkdir -p ~/.vnc
x11vnc -storepasswd "$VNC_PASSWORD" ~/.vnc/passwd
x11vnc -display :99 -localhost -rfbport 5900 -rfbauth ~/.vnc/passwd -forever -shared &
VNC_HOST=localhost
websockify --web /usr/share/novnc 6080 "${VNC_HOST}:5900" &
wait
```

The image:

```
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
      xvfb x11-utils openbox x11vnc novnc python3-websockify \
      xdotool xclip ffmpeg \
 && rm -rf /var/lib/apt/lists/*
RUN useradd -m agent
COPY --chown=agent start-desktop.sh /home/agent/start-desktop.sh
USER agent
WORKDIR /home/agent
CMD ["/bin/bash", "/home/agent/start-desktop.sh"]
```

Run it with an init process, more shared memory than the default, and the viewer port published only on the host's loopback interface. Docker's `--init` will "Run an init inside the container that forwards signals and reaps processes", and Docker warns that it "publishes the port on all interfaces" by default, so put a host address in front of the port in `-p` ([docker container run](https://docs.docker.com/reference/cli/docker/container/run/), read 2026-11-26). `/dev/shm` is 64 MB when `--shm-size` is left out ([Docker run reference](https://docs.docker.com/engine/containers/run/), read 2026-11-26), which is small for a browser on the desktop.

```
docker run --rm --init --shm-size=1g \
  -e VNC_PASSWORD="$(openssl rand -hex 12)" \
  -p "${HOST_LOOPBACK}:6080:6080" \
  agent-desktop
```

Set `HOST_LOOPBACK` to the host's loopback address, then open `/vnc.html` on port 6080 in a browser on that host.

## How do I check that the desktop is working?

Check the desktop by asking each part for proof, not by watching the logs.

1. `xdpyinfo -display :99` prints the screen; the dimensions should match the `-screen` value.
2. `xdotool getmouselocation` prints the pointer's position and screen.
3. Take one screenshot with FFmpeg and open it: the window manager's desktop should be visible.
4. Open the noVNC page, connect with the password, and confirm that a click from xdotool shows up in the viewer.

## What we read for this article

- [Xvfb manual, Debian bookworm](https://manpages.debian.org/bookworm/xvfb/Xvfb.1.en.html), read 2026-11-26
- [Xserver manual](https://xorg.freedesktop.org/archive/current/doc/man/man1/Xserver.1.xhtml), read 2026-11-26
- [xdpyinfo manual](https://manpages.debian.org/bookworm/x11-utils/xdpyinfo.1.en.html), read 2026-11-26
- [Openbox](https://openbox.org/), read 2026-11-26
- [xdotool manual](https://manpages.debian.org/bookworm/xdotool/xdotool.1.en.html), read 2026-11-26
- [FFmpeg devices](https://ffmpeg.org/ffmpeg-devices.html), read 2026-11-26
- [ffmpeg manual](https://ffmpeg.org/ffmpeg.html), read 2026-11-26
- [websockify](https://github.com/novnc/websockify), read 2026-11-26
- [novnc file list, Debian bookworm](https://packages.debian.org/bookworm/all/novnc/filelist), read 2026-11-26
- [python3-websockify file list, Debian bookworm](https://packages.debian.org/bookworm/all/python3-websockify/filelist), read 2026-11-26
- [docker container run](https://docs.docker.com/reference/cli/docker/container/run/), read 2026-11-26
- [Docker run reference](https://docs.docker.com/engine/containers/run/), read 2026-11-26

## FAQ

### Do I need a real graphics card to give an agent a Linux desktop?

No. Xvfb is an X server that, in its manual's words, can run on machines with no display hardware and no physical input devices. It keeps the screen in memory, which is all a screenshot-based agent needs.

### Why does an agent desktop need a window manager?

Xvfb provides the screen but does not decorate, place or focus windows. A light window manager such as Openbox gives windows title bars, focus and stacking, so dialogs and menus behave the way a model expects from screenshots of ordinary desktops.

### Is VNC needed for the agent to work?

No. The agent reads screenshots and sends input directly on the display. VNC and noVNC are for people who want to watch a run or take over, so they can be left out of unattended runs.

### Which display number should I use?

Any free one. xvfb-run uses 99 by default, which is a common choice for virtual displays; set DISPLAY to the same number for every program in the desktop.
