Skip to main content
The browser system driver provides sandboxed runtimes with filesystem and network capabilities that work in browser environments. It uses OPFS or an in-memory filesystem and fetch-based networking.
The same NodeRuntime class works in both Node.js and browser environments. The system driver and runtime driver factory determine where code actually runs — NodeRuntime is just the execution API.

Basic setup

createBrowserDriver is async because it needs to initialize the Origin Private File System (OPFS) before returning.
import {
  NodeRuntime,
  createBrowserDriver,
  createBrowserRuntimeDriverFactory,
} from "secure-exec/browser";

const runtime = new NodeRuntime({
  systemDriver: await createBrowserDriver(),
  runtimeDriverFactory: createBrowserRuntimeDriverFactory(),
});

Filesystem options

Choose between persistent OPFS storage or a transient in-memory filesystem.
  • OPFS (default) — backed by the browser’s Origin Private File System. Data persists across page reloads and browser restarts within the same origin. Falls back to in-memory if OPFS is unavailable.
  • In-memory — ephemeral storage that is discarded when the page unloads.
// Persistent (default)
const driver = await createBrowserDriver({ filesystem: "opfs" });

// In-memory
const driver = await createBrowserDriver({ filesystem: "memory" });

Networking

Enable the browser fetch adapter to allow sandboxed code to make HTTP requests.
const driver = await createBrowserDriver({
  useDefaultNetwork: true,
  permissions: { network: true },
});

Worker URL

Customize the worker script URL if you need to serve it from a specific path.
const runtimeDriver = createBrowserRuntimeDriverFactory({
  workerUrl: new URL("/workers/secure-exec.js", import.meta.url),
});

Differences from Node driver

  • Async creation: createBrowserDriver returns a Promise (OPFS initialization)
  • No child processes: CommandExecutor is not available
  • No DNS: only fetch-based networking, no dnsLookup
  • OPFS limitations: atomic rename and symlinks are not supported
  • No resource limits: memoryLimit, cpuTimeLimitMs, and timingMitigation are not available in the browser runtime