Deploying
An app that uses the SDK deploys as a static site. Your users’ Linux programs run in their browsers, so your server only serves files. With the hosted runtime frame, those are only your app’s own files: the engine and the default Linux image load from https://run.oxvm.dev. What your host has to get right is the headers, because the page must be cross-origin isolated.
Checklist
Section titled “Checklist”-
Install the SDK:
Terminal window npm install @oxvm/sdk -
Create VMs with
runtime: { hosting: "frame" }. -
Send
Cross-Origin-Opener-Policy: same-originandCross-Origin-Embedder-Policy: require-corpon every response, from your development server and from your host. -
If your app sends a Content Security Policy, allow the runtime frame and the preview origin in
frame-src; see Content Security Policy. -
Build and deploy, then open the deployed app and create a VM once.
The hosted runtime frame
Section titled “The hosted runtime frame”import { createVM } from "@oxvm/sdk";
const vm = await createVM({ mode: "userspace", runtime: { hosting: "frame" } });With runtime: { hosting: "frame" }, the SDK adds a hidden frame from https://run.oxvm.dev to your page and runs the engine there, together with its workers and the image downloads. Your page talks to the frame over a MessagePort, and the VM you get has the same methods as in any other setup.
- Your build contains no engine or image files, so there is nothing to stage, and nothing to keep in step with the SDK version.
- The page itself must be cross-origin isolated. Otherwise
createVMrejects withFEATURE_NOT_AVAILABLE,detail.reason: "browser-unsupported"anddetail.requirement: "cross-origin-isolation". - Userspace JavaScript acceleration needs no setup: the frame provides its execution origin.
- Previews need no setup either: VMs in the frame serve them from
https://<session>.tabvm.devunless you pass your ownprevieworigin. - Your own command interceptor workers need a self-hosted engine; the frame runs only the packaged interceptor.
- WebAssembly modules run in the frame too, in a module frame it serves itself. Your page still serves the modules’ staged files from its own origin.
- The frame downloads images you host yourself, so their server must allow it. See Custom images.
- Public sites need a registered license token. Pass it as
runtime: { hosting: "frame", license }. Missing or rejected tokens fail creation withPERMISSION_DENIED. Local development needs no token. See Licenses for registration, eligibility and renewal.
runtime.origin points the frame at another runtime origin. Leave it out for https://run.oxvm.dev.
Send the isolation headers
Section titled “Send the isolation headers”Cross-Origin-Opener-Policy: same-originCross-Origin-Embedder-Policy: require-corpEvery response of your app needs both headers: the HTML page, scripts, cached responses and error pages, and with a self-hosted engine also its worker, .wasm and image files. Without them the page is not cross-origin isolated, and the engine cannot share memory between its workers. Do not work around a missing header with a browser flag.
With require-corp, anything your page loads from another origin (fonts, scripts, images) needs a Cross-Origin-Resource-Policy header or CORS. Serve the app over HTTPS; http://localhost works during development. See Browser requirements.
import { defineConfig } from "vite";
const headers = { "Cross-Origin-Opener-Policy": "same-origin", "Cross-Origin-Embedder-Policy": "require-corp",};
export default defineConfig({ optimizeDeps: { exclude: ["@oxvm/sdk"] }, worker: { format: "es" }, server: { headers }, preview: { headers },});optimizeDeps.exclude stops Vite from pre-bundling the SDK, which would break the URLs of its workers. worker.format: "es" builds them as module workers. The headers cover vite dev and vite preview; set the same headers on your host. With a self-hosted engine, run assets install before vite build, because Vite copies public/ into the build output.
Next.js
Section titled “Next.js”- Create VMs only in client code: a
"use client"component, insideuseEffector an event handler. Importing@oxvm/sdkduring server rendering is safe, butcreateVMneeds a browser. - Add the headers with
headers()innext.config.ts. Withoutput: "export", Next.js does not applyheaders(); set the headers on your static host instead.
import type { NextConfig } from "next";
const nextConfig: NextConfig = { async headers() { return [ { source: "/:path*", headers: [ { key: "Cross-Origin-Opener-Policy", value: "same-origin" }, { key: "Cross-Origin-Embedder-Policy", value: "require-corp" }, ], }, ]; },};
export default nextConfig;"use client";
import { useEffect, useState } from "react";import { createVM } from "@oxvm/sdk";
export function LinuxArch() { const [text, setText] = useState("Starting Linux");
useEffect(() => { let active = true; const opening = createVM({ mode: "userspace", runtime: { hosting: "frame" } }); opening .then((vm) => vm.exec({ command: "uname", args: ["-m"] })) .then((result) => { if (active) setText(new TextDecoder().decode(result.stdout)); }) .catch((error: unknown) => { if (active) setText(error instanceof Error ? error.message : "Linux did not start"); }); return () => { active = false; opening.then((vm) => vm.dispose()).catch(() => undefined); }; }, []);
return <pre>{text}</pre>;}Static hosts with a _headers file
Section titled “Static hosts with a _headers file”Hosts that read a _headers file from the published folder, such as Netlify and Cloudflare Pages, take the headers from public/_headers:
/* Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corpContent Security Policy
Section titled “Content Security Policy”With the hosted frame, the engine compiles and runs inside the frame, under the frame’s own policy. If your app sends a Content Security Policy, it only has to allow the frames:
| The SDK | Directive |
|---|---|
| Embeds the hidden runtime frame | https://run.oxvm.dev in frame-src |
| Embeds hidden frames from the preview origin | https://*.tabvm.dev in frame-src, or your own preview origin with a wildcard for per-session hosts |
A starting point, to merge with what the rest of your app needs:
Content-Security-Policy: default-src 'self'; frame-src https://run.oxvm.dev https://*.tabvm.devA self-hosted engine runs in your page and needs more; see its policy.
Self-hosting the engine
Section titled “Self-hosting the engine”Licensed customers can serve an engine release from their own site instead of using the frame. The page then loads the engine directly, and your host serves the engine and image files next to your app.
-
Install the CLI next to the SDK, and keep both on the same exact version:
Terminal window npm install --save-dev @oxvm/cli -
Add
oxvm.config.tsand runoxvm assets installbefore every build. -
Create VMs with
runtime: { hosting: "self-hosted", baseUrl: "/oxvm/runtime/", license }. -
Send the isolation headers on every response, the engine and image files included.
-
For Userspace, host an execution origin or create VMs with
commandInterceptors: "off"; see Userspace JavaScript acceleration. -
Build and deploy the complete output, including the staged
/oxvm/files and the SDK’s worker files. -
Run
oxvm doctoragainst the deployed URL.
Stage the engine and image files
Section titled “Stage the engine and image files”The SDK package does not contain the engine. oxvm assets install copies it, together with an image, into your static folder. Configure it in oxvm.config.ts at your project root:
import type { ProjectConfig } from "@oxvm/sdk/image-builder";
export default { mode: "userspace", publicDir: "public", assetBaseUrl: "/oxvm/",} satisfies ProjectConfig;| Field | Default | Meaning |
|---|---|---|
mode |
Required | "userspace" or "system": which default image to stage. |
publicDir |
"public" |
Your bundler’s static folder. |
assetBaseUrl |
"/oxvm/" |
The URL path the files are served under. It must end with /. |
npx oxvm assets installThe command verifies and copies the engine release your SDK version pins (runtime/), the default image for mode (images/), and a few files that oxvm doctor uses. The browser checks the engine files against the same pins before it runs them, so files from another SDK version fail with CORE_LOAD_FAILED.
The first run writes oxvm.lock.json with the exact SDK, CLI, engine and image. Commit it. For a self-hosted build, stage the files in CI before the build. Next.js serves public/ at the site root, so the defaults work with it. To stage your own images, see Custom images.
After you upgrade the SDK and CLI to the same version, run npx oxvm assets install --update-lock with the options you use to stage the project. The CLI stages and verifies the assets before it replaces the lock. Review the lock changes and rebuild. See Update an existing project for legacy configuration and asset paths.
Point createVM at the files
Section titled “Point createVM at the files”import { createVM } from "@oxvm/sdk";
export function openVM(license: string) { return createVM({ mode: "userspace", runtime: { hosting: "self-hosted", baseUrl: "/oxvm/runtime/", license }, commandInterceptors: "off", // until you host an execution origin, see below });}/oxvm/runtime/ is where assets install stages the engine with the default assetBaseUrl, and a createVM call without runtime loads the engine from there, without a license token. On localhost the engine runs without one, so leave license out of runtime during local development.
If you change assetBaseUrl, pass runtime: { hosting: "self-hosted", baseUrl: "<assetBaseUrl>runtime/" }, and for the default image image: defaultImage(mode, url), with the image.manifestUrl that your project lock records.
File types and fallbacks
Section titled “File types and fallbacks”- Serve
.wasmfiles asapplication/wasm, scripts (workers included) as JavaScript, and the image.jsonfiles asapplication/json. - If your host answers unknown paths with
index.html(a single-page-app fallback), exclude/oxvm/and your build’s script files from it. A missing file must return 404, not HTML. - Deploy the whole build output. The SDK starts its workers from files your bundler emits next to the main bundle.
Content Security Policy for a self-hosted engine
Section titled “Content Security Policy for a self-hosted engine”If your app sends a Content Security Policy, add these sources to it:
| The SDK | Directive |
|---|---|
| Compiles WebAssembly, including code it generates while guest programs run | 'wasm-unsafe-eval' in script-src |
| Starts module workers from your origin | 'self' in worker-src |
Loads engine and image files from your origin, and reads the verified engine modules through blob: URLs inside its workers |
'self' and blob: in connect-src |
| Embeds hidden frames from your preview origin | The preview origin in frame-src, with a wildcard for per-session hosts |
| Opens the module frame of a VM that runs WebAssembly modules | 'self' in frame-src |
| Connects to a relay | The relay in connect-src: http://127.0.0.1:7337 and ws://127.0.0.1:7337 for a personal relay, or your relay server’s https: and wss: origin |
A starting point for an app with per-session previews, to merge with what the rest of your app needs:
Content-Security-Policy: default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; worker-src 'self' blob:; connect-src 'self' blob:; frame-src https://*.preview.example.comThe content-security-policy check of oxvm doctor compiles the engine modules and starts a worker from a blob: URL, so the policy must also allow blob: workers for that check to pass.
Userspace JavaScript acceleration
Section titled “Userspace JavaScript acceleration”Userspace VMs default to commandInterceptors: "auto", which runs some JavaScript processes in browser workers on a separate execution origin. The hosted frame provides one. A self-hosted engine finds it through native-node-api.json in the runtime folder: /oxvm/runtime/native-node-api.json with the default layout. oxvm assets install does not create this file.
To host an execution origin:
- Serve the SDK’s
assets/native-process/folder at/oxidevm-native-process/on a separate HTTPS origin that holds no application cookies, credentials or storage. Use the files of the SDK version your app uses. - Send
Cross-Origin-Opener-Policy: same-origin,Cross-Origin-Embedder-Policy: require-corpandCross-Origin-Resource-Policy: cross-originthere, with a CSP ofdefault-src 'none'; script-src 'self' 'unsafe-eval'; worker-src 'self'; connect-src 'none'plusframe-ancestorsnaming your app’s origin. - Put
{"version":1,"origin":"https://exec.example.com"}innative-node-api.jsonnext to the engine files, and allow that origin in your app’sframe-src.
See commandInterceptors for what the option changes.
WebAssembly modules
Section titled “WebAssembly modules”Modules run with a self-hosted engine or the hosted runtime frame. oxvm wasm add writes the declaration and lock to commit and stages each module’s files under .oxvm/modules/<id>/<release>/. Run oxvm wasm stage before a production build on a fresh clone. The generated handles name those files with new URL(path, import.meta.url), so bundlers copy them as assets, or inline small files as data: URLs. Both forms are checked against the lock. Your page reads them with fetch, so allow data: in connect-src when files are inlined.
Ship the notices a module’s license requires, and the source offer for a copyleft module, with your application.
Serve the module frame
Section titled “Serve the module frame”Module code runs in a per-VM module frame with an opaque origin, never in your page’s origin. The hosted runtime frame serves its own. With a self-hosted engine you serve it:
- Copy the SDK’s
assets/module-frame/folder (index.html,broker.js,runner.jsandframe.json) fromnode_modules/@oxvm/sdk/tomodule-frame/beside the engine files, that is<runtime.baseUrl>module-frame/. With the default layout that ispublic/oxvm/runtime/module-frame/.oxvm assets installdoes not copy it. Copy it again after every SDK upgrade: its scripts speak that SDK version’s protocols. - Send the headers listed under
headersin thatframe.jsonon every response undermodule-frame/, instead of your app’s own policy. Serveindex.htmlastext/htmland the scripts as JavaScript, and keep any Service Worker of yours away from these paths.
The headers look like this; copy the exact values from frame.json, because the policy names the bootstrap script by its sha256:
Content-Security-Policy: sandbox allow-scripts; default-src 'none'; script-src 'sha256-<bootstrap>' blob: 'wasm-unsafe-eval' 'unsafe-eval'; worker-src blob:; connect-src blob:; frame-ancestors *; base-uri 'none'; form-action 'none'Cross-Origin-Embedder-Policy: require-corpCross-Origin-Resource-Policy: cross-originX-Content-Type-Options: nosniffReferrer-Policy: no-referrer- The policy must be a header, never a
<meta>element. Only the header carriessandbox, which keeps the document opaque even when someone opens it directly. Cross-Origin-Resource-Policymust becross-origin: Firefox checks it against the frame’s opaque origin and refuses to load the frame withsame-origin.connect-src blob:is deliberate. Module code has no browser network; it uses the VM’s (see Module networking).
A frame that does not load makes spawnModule and enableModuleCommands fail with FEATURE_NOT_AVAILABLE, detail.reason: "wasm-module-isolation-unavailable" and detail.capability: "frame-load". A missing broker.js or runner.js fails with CORE_LOAD_FAILED and detail.reason: "module-frame-asset". Your page’s own policy needs 'self' in frame-src for the module frame.
Check the deployment
Section titled “Check the deployment”npx oxvm doctor https://app.example.com/npx oxvm doctor https://app.example.com/ --preview-origin https://preview.example.com --browser firefox --jsondoctor opens the URL in a headless browser (--browser chromium, firefox or webkit; Chromium by default) and checks what the host actually serves. Without a URL it checks http://localhost:5173/. It exits with status 3 when a check fails, so CI can stop a release, and --json prints one JSON report.
| Check | Passes when |
|---|---|
secure-context |
The page is served over HTTPS or from localhost. |
cross-origin-isolation |
The page is cross-origin isolated and its response carries COOP same-origin and COEP require-corp. |
wasm-features |
The browser has the features the SDK needs. |
asset-integrity |
The staged engine files and doctor files match the installed SDK release. |
wasm-mime |
The engine modules are served as application/wasm. |
worker-load |
Module workers load from the staged files. |
content-security-policy |
The page’s CSP allows WebAssembly compilation and a blob: worker. |
storage |
The browser reports a storage quota and can write a test file. |
preview-origin |
With --preview-origin, the preview files register their Service Worker; otherwise not-configured. |
lock |
The project lock matches the installed SDK; not-configured without a project config. |
Add <meta name="oxvm-assets" content="/oxvm/"> to your self-hosted page so doctor can find the staged files. Use your configured assetBaseUrl for the tag’s content. Without the tag, doctor probes the legacy /oxidevm/ path.
doctor loads its own copies of the SDK workers, so it does not prove that your bundler emitted the workers your app uses. Open the deployed app and create a VM once as well.
An app on the hosted runtime frame serves no engine files, and doctor checks the frame instead: the page’s isolation and features, and whether this SDK release’s frame loads under your page’s policy and serves the pinned engine. worker-load and storage are then not-applicable. --hosting frame or --hosting self-hosted chooses explicitly; see oxvm doctor.
Keep older image files online
Section titled “Keep older image files online”assets install stages custom images under images/<manifest digest>/, a new directory for every version. When you deploy a new version, keep the earlier directories on your host: restore points and durable workspaces can refer to the image they were made on. Publish each image directory complete, and never edit the files in it.