Skip to content

Run the code editor VS Code in a sandbox on a screen in memory, watch and drive it over VNC, and take screenshots of it.

A sandbox has no screen of its own. display gives it one, where GUI programs run as on a desktop: a person watches and takes over from a VNC viewer, and code takes screenshots of it. The image needs the GUI program. This guide runs VS Code as its example.

Show a program on a screen

Give the sandbox display and the VNC port, 5900. display run -- <program> shows the program on a screen and says ready once a viewer can connect; then connect one through a port forwarder.

This builds an image with VS Code in it, as Working with images shows, and opens it on /root:

from virtx import PortForwarder, Recipe, Stdout
await client.build_image(
Recipe("debian:bookworm-slim").run(
# VS Code needs libx11-xcb1 to start, and its package does not install it
"apt-get update && apt-get install -y --no-install-recommends ca-certificates curl libx11-xcb1 fonts-dejavu-core"
" && curl -fsSL -o /tmp/code.deb https://update.code.visualstudio.com/latest/linux-deb-$(dpkg --print-architecture | sed s/amd64/x64/)/stable"
" && apt-get install -y --no-install-recommends /tmp/code.deb"
),
"vscode:latest"
).complete()
sandbox = await client.create_sandbox("vscode:latest", abins=["display"], ports=[5900])
async for entry in sandbox.exec(
["display", "run", "--password", "secret", "--",
"code", "--wait", "--no-sandbox", "--user-data-dir", "/tmp/code", "/root"]
):
if isinstance(entry.entry, Stdout) and entry.entry.line == "ready":
break # the screen keeps running
with await PortForwarder.open(sandbox, 5900) as forwarder:
print(f"vnc://{forwarder.local}")
input("Press Enter to stop watching")

VS Code runs as root here, which takes --no-sandbox and a --user-data-dir, and --wait keeps display run up while its window is.

A VNC viewer showing the sandbox's screen, with VS Code open on a folder.

In the viewer you see the program, and type and click in it as on your own desktop. The screen stays up as long as the program runs.

display run --help lists its options, such as the screen’s size.

Let an AI agent use the screen

An AI agent that works a GUI program needs to see the screen, with no person watching. These commands are what it looks with:

display shot /tmp/screen.png # what the screen shows now, as a PNG
display cursor # where the pointer is, and the cursor's name: 640 360 xterm

An agent learns them from /abin/skills/display/SKILL.md, and an Ailoy agent is given it by itself.

What does not run

Programs that need OpenGL from the X server (GLX) do not start on this screen.