Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/ozwell-cloudflare/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!Dockerfile
!desktop.sh
2 changes: 2 additions & 0 deletions examples/ozwell-cloudflare/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.dev.vars
.wrangler/
19 changes: 19 additions & 0 deletions examples/ozwell-cloudflare/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ghcr.io/mieweb/ozwell-computer:v2026.11.4

USER root
ADD https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb /tmp/chrome.deb
RUN apt-get update \
&& apt-get install -y --no-install-recommends /tmp/chrome.deb tini xauth xvfb dbus-daemon \
&& rm -rf /var/lib/apt/lists/* /tmp/chrome.deb \
&& install -d -m 0700 -o desktop -g desktop /home/desktop/run \
&& install -d -m 1777 /tmp/.X11-unix /tmp/.ICE-unix

COPY --chmod=755 desktop.sh /usr/local/bin/ozwell-trial-desktop
ENV HOME=/home/desktop DISPLAY=:0 XDG_RUNTIME_DIR=/home/desktop/run \
XDG_SESSION_TYPE=x11 LIBGL_ALWAYS_SOFTWARE=1 \
OZWELL_COMPUTER_HOST=0.0.0.0 OZWELL_COMPUTER_UPDATE_URL=off
USER desktop
WORKDIR /home/desktop
EXPOSE 8080
STOPSIGNAL SIGTERM
ENTRYPOINT ["/usr/bin/tini", "-g", "--", "/usr/bin/xvfb-run", "--server-num=0", "--server-args=-screen 0 1280x800x24 -nolisten tcp +extension RANDR +extension DAMAGE", "/usr/bin/dbus-run-session", "--", "/usr/local/bin/ozwell-trial-desktop"]
8 changes: 8 additions & 0 deletions examples/ozwell-cloudflare/desktop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -eu
: "${OZWELL_COMPUTER_TOKEN:?Set the desktop access token before starting Ozwell}"

startxfce4 &
google-chrome-stable --ozone-platform=x11 --disable-dev-shm-usage \
--no-first-run --no-default-browser-check --new-window about:blank &
exec /usr/bin/node /opt/ozwell-computer/dist/cli.js
102 changes: 102 additions & 0 deletions examples/ozwell-cloudflare/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { DurableObject } from "cloudflare:workers";

const idleTimeout = 10 * 60 * 1000;

export class OzwellDesktop extends DurableObject {
starting;

constructor(ctx, env) {
super(ctx, env);
if (ctx.container.running) {
ctx.blockConcurrencyWhile(() => ctx.container.setInactivityTimeout(idleTimeout));
}
}

async ready() {
const container = this.ctx.container;
if (!container.running) {
container.start({
image: container.images.desktop,
instance: "standard-3",
enableInternet: true,
env: { OZWELL_COMPUTER_TOKEN: this.env.OZWELL_COMPUTER_TOKEN },
});
}
await container.setInactivityTimeout(idleTimeout);
const port = container.getTcpPort(8080);
const deadline = Date.now() + 90_000;
while (Date.now() < deadline) {
try {
const res = await port.fetch("http://desktop/health", {
headers: { connection: "close" }, signal: AbortSignal.timeout(1500),
});
await res.body?.cancel();
if (res.status === 204) return;
} catch {
// The port is unavailable while the desktop boots.
}
await scheduler.wait(500);
}
throw new Error("Ozwell did not become ready on port 8080");
}

async fetch(request) {
if (!this.ctx.container.running || this.starting) {
this.starting ??= this.ready().finally(() => { this.starting = undefined; });
try {
await this.starting;
} catch (error) {
console.error("Desktop startup failed", error);
return new Response("Desktop is starting or failed to start. Retry, then check Wrangler logs.", {
status: 503, headers: { "Retry-After": "5" },
});
}
}
const url = new URL(request.url);
const scheme = url.protocol.slice(0, -1);
url.protocol = "http:";
url.hostname = "desktop";
url.port = "";
const forwarded = new Request(url, request);
forwarded.headers.delete("host");
if (!forwarded.headers.has("upgrade")) forwarded.headers.set("connection", "close");
forwarded.headers.set("x-forwarded-proto", scheme);
const port = this.ctx.container.getTcpPort(8080);
try {
return await port.fetch(forwarded);
} catch (error) {
// A reused local Wrangler connection can close between requests.
if (forwarded.headers.has("upgrade") || !["GET", "HEAD"].includes(request.method)) throw error;
return port.fetch(new Request(url, { method: request.method, headers: forwarded.headers }));
}
}
}

export default {
async fetch(request, env) {
const token = env.OZWELL_COMPUTER_TOKEN;
if (!token) return new Response("Desktop secret missing", { status: 503 });
const url = new URL(request.url);
if (request.method === "POST" && url.pathname === "/login") {
const form = new URLSearchParams(await request.text());
if (form.get("token") !== token) return new Response("Incorrect desktop token", { status: 401 });
const secure = url.protocol === "https:" ? "; Secure" : "";
return new Response(null, { status: 303, headers: {
Location: "/",
"set-cookie": `ozwell_computer_token=${token}; Path=/; HttpOnly; SameSite=Lax${secure}`,
"cache-control": "no-store",
} });
}
const cookie = (request.headers.get("cookie") || "").split(";").map(part => part.trim());
if (!cookie.includes(`ozwell_computer_token=${token}`) &&
request.headers.get("authorization") !== `Bearer ${token}`) {
if (request.method === "GET" && url.pathname === "/") {
return new Response('<!doctype html><title>Ozwell trial</title><form action="/login" method="post"><label>Desktop token <input name="token" type="password" required autofocus></label> <button>Open desktop</button></form>', {
headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store", "referrer-policy": "no-referrer" },
});
}
return new Response("Desktop token required", { status: 401 });
}
return env.DESKTOP.getByName("trial").fetch(request);
},
};
16 changes: 16 additions & 0 deletions examples/ozwell-cloudflare/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "ozwell-x11-trial",
"main": "worker.js",
"compatibility_date": "2026-11-01",
"workers_dev": true,
"containers": [{
"class_name": "OzwellDesktop",
"scheduling_policy": "durable_object",
"images": { "desktop": { "dockerfile": "./Dockerfile" } }
}],
"durable_objects": {
"bindings": [{ "name": "DESKTOP", "class_name": "OzwellDesktop" }]
},
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["OzwellDesktop"] }],
"secrets": { "required": ["OZWELL_COMPUTER_TOKEN"] }
}
90 changes: 90 additions & 0 deletions test Cloudflare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Try Ozwell Computer on Cloudflare

This starts one XFCE desktop with a visible Google Chrome window. You can use Chrome through the browser viewer and inspect the same window through Ozwell’s API or MCP. The [standalone example](examples/ozwell-cloudflare/) uses the published Ozwell image and Wrangler directly. You can copy that directory anywhere and start at step 2.

Verified with local Wrangler on an Apple Silicon Mac. The viewer opened **Example Domain** in Chrome, Ozwell reported the matching X11 window title, and the MCP screenshot tool returned a PNG. The Cloudflare deployment command passed a dry run. A live account deployment is the remaining test.

## 1. Open the example

From the root of this repository, run:

```sh
cd examples/ozwell-cloudflare
```

You’ll need a Cloudflare account on the **Workers Paid** plan with Containers enabled, a working Docker engine, Node.js 22.12 or newer, and OpenSSL. On a Mac, Docker Desktop or OrbStack can build the Linux amd64 image. Allow several minutes for the first build and upload. [Cloudflare Containers quickstart](https://developers.cloudflare.com/containers/get-started/)

## 2. Set up Wrangler and a desktop token

Use the same terminal for the remaining commands. This shell function pins the Wrangler version. The token grants control of the desktop. The command generates it once and saves it in a private, Git-ignored file excluded from the Docker image.

```sh
wrangler_trial() { npx --yes wrangler@4.169.1 "$@"; }
docker info >/dev/null
wrangler_trial --version
test -f .dev.vars || (umask 077 && printf 'OZWELL_COMPUTER_TOKEN=%s\n' "$(openssl rand -hex 32)" > .dev.vars)
```

## 3. Deploy

If you want to preview the exact setup locally first, run `wrangler_trial dev --local`, open the localhost URL it prints, and sign in as described in step 4. Press Ctrl-C when finished. To run on Cloudflare, continue below.

```sh
wrangler_trial login
wrangler_trial whoami
```

Confirm the account shown by `whoami`. The [Wrangler config](examples/ozwell-cloudflare/wrangler.jsonc) names the Worker **ozwell-x11-trial**. If that name already belongs to another Worker in your account, change the `name` field before deploying.

```sh
wrangler_trial deploy --secrets-file .dev.vars
```

Wrangler builds the desktop image, uploads it, and prints the Worker’s HTTPS URL. Copy that exact URL. [Deploying Containers](https://developers.cloudflare.com/containers/guides/deploy/) · [Deploying Worker secrets](https://developers.cloudflare.com/workers/configuration/secrets/#upload-secrets-alongside-code)

## 4. Open Chrome and verify the agent sees it

1. Open the Worker URL in your browser. On macOS, copy the token with the command below, paste it into **Desktop token**, and click **Open desktop**. On other platforms, copy the value after `=` from `.dev.vars`.

```sh
cut -d= -f2- .dev.vars | tr -d '\n' | pbcopy
```

2. The first authenticated request starts the computer. Once the XFCE viewer opens, click the Chrome window and visit **https://example.com**. You should see **Example Domain**.
3. Set `TRIAL_URL` to the URL Wrangler printed, without a trailing slash, and list the windows. Look for `Google-chrome` and the page title. This checks the actual X11 window, including input from the viewer.

```sh
TRIAL_URL='https://ozwell-x11-trial.YOUR-SUBDOMAIN.workers.dev'
. ./.dev.vars
curl --fail-with-body -sS -H "Authorization: Bearer $OZWELL_COMPUTER_TOKEN" \
"$TRIAL_URL/api/v1/windows"
```

4. To see the agent’s view, save a screenshot. For an MCP client that supports Streamable HTTP, use `$TRIAL_URL/mcp` with the same Bearer token and call the `screenshot` tool. [Ozwell API and MCP](https://github.com/mieweb/ozwell-computer/tree/v2026.11.4#architecture)

```sh
curl --fail -sS -H "Authorization: Bearer $OZWELL_COMPUTER_TOKEN" \
"$TRIAL_URL/api/v1/screenshot?max_dimension=1280" -o /tmp/ozwell-desktop.png
```

The trial uses one `standard-3` instance (2 vCPUs, 8 GiB RAM). Closing the viewer and stopping API traffic lets the ten-minute inactivity timeout take effect. This trial starts from the image after a cold start, so Chrome and Firefox return, while apps installed interactively and browser-profile changes are temporary. [Instance sizes](https://developers.cloudflare.com/containers/platform/limits/) · [Sandbox lifetime](https://developers.cloudflare.com/sandbox/concepts/lifetime/)

## 5. Inspect or remove the trial

If the first request returns 503, wait a few seconds and retry. If the desktop opens without Chrome, open an XFCE terminal in the viewer and run `google-chrome-stable --ozone-platform=x11 --disable-dev-shm-usage` to see its startup error. In a second terminal, run the following from the example directory to check logs and instance state. Use the application ID associated with **this trial** in the list.

```sh
npx --yes wrangler@4.169.1 containers list
TRIAL_APP_ID='paste-the-trial-application-uuid-here'
npx --yes wrangler@4.169.1 containers instances "$TRIAL_APP_ID"
npx --yes wrangler@4.169.1 tail
```

When finished, close the viewer and press Ctrl-C in the log terminal. In that same terminal, delete the trial Container application and the Worker named in this directory’s config. These commands discard the trial desktop. [Wrangler Container commands](https://developers.cloudflare.com/workers/wrangler/commands/containers/)

```sh
npx --yes wrangler@4.169.1 containers delete "$TRIAL_APP_ID"
npx --yes wrangler@4.169.1 delete
```

If you also want to remove the uploaded image, find its exact tag with `npx --yes wrangler@4.169.1 containers images list` and pass just that trial tag to `npx --yes wrangler@4.169.1 containers images delete`.
Loading