Browser desktop template
This template runs a lightweight Openbox desktop on a virtual display. noVNC serves the desktop in a browser on port 6080.
mjs
import { Sandbox, Template, waitForURL } from "@abox-dev/sdk";
const templateName = process.env.TEMPLATE_NAME ?? "browser-desktop";
const template = Template({ fileContextPath: "." })
.fromUbuntuImage("24.04")
.aptInstall([
"novnc",
"openbox",
"scrot",
"websockify",
"x11vnc",
"xdotool",
"xterm",
"xvfb",
])
.copy("start-desktop.sh", "/usr/local/bin/start-desktop", {
mode: 0o755,
user: "root",
})
.setStartCmd(
"/usr/local/bin/start-desktop",
waitForURL("http://localhost:6080/vnc.html"),
);
await Template.build(template, templateName, {
cpuCount: 2,
memoryMB: 2_048,
});
const sandbox = await Sandbox.create(templateName);
try {
const response = await sandbox.commands.run(
"curl --silent --head http://localhost:6080/vnc.html | head -n 1",
);
console.log(response.stdout);
} finally {
await sandbox.kill();
}Keep start-desktop.sh next to the example source. The script starts Xvfb, Openbox, x11vnc, and the noVNC web proxy. The ready command waits for vnc.html, so the browser client is available as soon as the sandbox starts. The image also includes xdotool for keyboard and pointer input, scrot for screenshots, and xterm as a lightweight terminal.
To open the desktop outside the sandbox, prepend https:// to sandbox.getHost(6080) in JavaScript or sandbox.get_host(6080) in Python and append /vnc.html.