Skip to content
Esc

    Search bindings, commands, errors and guides.

    Compute / Worker Loader

    Compute

    Worker Loader

    Load and run dynamic Workers at runtime with the worker_loaders binding, each in its own Node.js process inside an agentOS VM.

    Partial

    Runs on One Node.js process per dynamic Worker in an agentOS VM, never on the host, Workers RPC over Cap'n Web

    Works
    get(), load(), fetch(), WebSockets, and RPC, with env and props capabilities and globalOutbound
    Differs
    Each dynamic Worker runs in its own agentOS VM. A load usually takes a prewarmed VM; when none is ready, it waits about 0.3 seconds for one to boot. Compatibility settings and limits are ignored.
    Missing
    getDurableObjectClass(), connect() to a dynamic Worker, Python modules, and tail events from dynamic Workers
    Migration
    Not needed Dynamic Workers are code that the Worker loads at runtime.
    Configure
    worker_loaders

    A Worker Loader runs code that your Worker hands it at runtime, as a dynamic Worker you call with fetch() or RPC. On OpenOrange, each dynamic Worker runs in its own agentOS VM.

    Quickstart

    1. Bind the loader

      Add a worker_loaders binding to wrangler.jsonc.

      {
        "name": "my-worker",
        "main": "src/index.ts",
        "compatibility_date": "2026-09-03",
        "worker_loaders": [{ "binding": "LOADER" }]
      }
    2. Write the dynamic Worker

      The code is an object of modules. globalOutbound: null blocks the dynamic Worker’s own fetch().

      const code = {
        compatibilityDate: "2026-09-03",
        mainModule: "main.js",
        modules: {
          "main.js": `export default {
            fetch() { return new Response("Hello from a dynamic Worker"); },
          };`,
        },
        globalOutbound: null,
      };
    3. Load it and call it

      get() keeps one dynamic Worker per name. Call it with fetch() or RPC through its entrypoint.

      export default {
        async fetch(request, env): Promise<Response> {
          const worker = env.LOADER.get("hello", () => code);
          return worker.getEntrypoint().fetch(request);
        },
      } satisfies ExportedHandler<Env>;
    4. Run it

      Start orange dev, then request the Worker.

      orange dev
      curl localhost:8787
      Hello from a dynamic Worker

    How it works

    • Dynamic Worker code is untrusted, so each dynamic Worker gets its own VM, as it gets its own isolate on Cloudflare. It never runs on the host.
    • Orange keeps a few VMs booted ahead of use, so a new dynamic Worker only writes its own modules. Each VM runs one dynamic Worker and is never reused.
    • A dynamic Worker stops when it is idle or nothing references it. Its VM is disposed, never returned to the pool.
    • Your Worker and the dynamic Worker talk Workers RPC, so stubs and bindings you pass in env or props work across the boundary.
    AI context Compatibility, limits and details

    Written for LLMs and coding agents: every edge case, measurement, and known deviation. You do not need it to use the feature.

    Compatibility

    FeatureStatusNotes
    get(name, getCode)SupportedOne dynamic Worker per name in each binding.
    get(null, getCode) and load(code)SupportedEach call starts a new dynamic Worker.
    fetch() and RPC through getEntrypoint()SupportedStubs, RpcTargets, functions, service bindings, and Durable Object stubs travel by reference.
    env and propsSupportedStubs, service bindings, and Durable Object stubs pass by reference and work for as long as the dynamic Worker runs. RpcTargets and functions pass by reference too.
    globalOutboundSupportednull makes fetch() reject and connect() throw. A Fetcher receives the dynamic Worker’s fetch() calls.
    JavaScript, CommonJS, text, data, JSON, and Wasm modulesSupportedPass Wasm as bytes. Relative, cloudflare:*, and node:* imports resolve as in the parent Worker. A name that is not relative, such as a.js or a URL, names a module from the bundle root, also in an import() computed at runtime. workerd resolves that name from the importer’s folder, so the two differ only for an importer in a subfolder.
    Wasm exception handling with exnref (try_table, throw_ref), as Rust panic=unwind builds useSupportedOn by default, as in workerd. See The VM runtime.
    A WebSocket through fetch()SupportedThe dynamic Worker answers with a WebSocketPair end in a 101 response, and your Worker returns that response. See WebSockets.
    A node:http server through cloudflare:nodeSupportedAn Express app serves requests.
    upgrade on a node:http serverOrange extensionA WebSocket request reaches the server’s upgrade listener with a socket, so the ws package and dev servers such as next dev accept it. See WebSockets.
    mountsOrange extensionMounts a project directory read-only, or an empty writable directory, into the VM. See Mounts.
    vmLimitsOrange extensionGives the dynamic Worker’s VM more V8 heap or CPU time than the agentOS default, up to a runtime cap. See VM limits.
    idleTimeoutMsOrange extensionSets this Worker’s idle time before it stops, from 1 to 2147483647 ms, in place of ORANGE_WORKER_LOADER_IDLE_TIMEOUT_MS. An idle Worker still gives up its slot when a new Worker needs one. A value out of range fails the load with a TypeError.
    Python modules and compiled WebAssembly.Module valuesNot supportedThrow a TypeError.
    getDurableObjectClass()Not supportedThrows a NotSupportedError.
    connect() on an entrypoint, or through a Fetcher globalOutboundNot supportedThrows.
    compatibilityDate, compatibilityFlags, allowExperimental, and limitsPartialAccepted and ignored. The dynamic Worker uses the parent’s compatibility profile.
    tails and streamingTailsNot supportedAccepted. They receive no events.

    Limits

    Orange does not copy Cloudflare’s 64 MiB code and 1 MiB env limits. agentOS’s limits apply:

    WhatLimitWhat happens over it
    One JavaScript or CommonJS moduleNo set limit. In a test, 17 MiB worked.Orange adds no check.
    One text, JSON, Wasm, or data moduleNo set limit. In a test, 20 MiB worked.Orange adds no check.
    envNo set limit. In a test with agentOS 0.4.1, 5 MiB worked.At 10 MiB, the dynamic Worker exited with code 1.
    Running dynamic Workers, across all Worker Loader bindings32. Set ORANGE_WORKER_LOADER_MAX_WORKERS to change it.A new dynamic Worker stops the least recently used idle one. If none is idle, get() or load() throws a WorkerLoaderLimitError that names the limit. At 80% of the limit, orange dev logs a warning.
    Idle time before a dynamic Worker stops30 seconds. Set ORANGE_WORKER_LOADER_IDLE_TIMEOUT_MS to change it, from 1 to 2147483647, or idleTimeoutMs on one Worker’s code object.The dynamic Worker stops and frees its VM. The next call loads it again. A value out of range stops orange dev at startup with a RangeError that names the setting.
    Prewarmed VMs2 for each network mode by default, from 0 to 16 with ORANGE_WORKER_LOADER_POOL_SIZEA load that finds the pool empty boots its own VM.
    vmLimits.heapMb4096 by default. Set ORANGE_WORKER_LOADER_MAX_VM_HEAP_MB to change it, from 1 to 65536.The load throws a WorkerLoaderLimitError that names the setting.
    vmLimits.cpuTimeMs1800000 (30 minutes) by default. Set ORANGE_WORKER_LOADER_MAX_VM_CPU_TIME_MS to change it, from 1 to 2147483647.The load throws a WorkerLoaderLimitError that names the setting.
    Bytes that one WebSocket holds for a side that has not taken them, in each direction. One message counts in full.4194304 (4 MiB) by default. Set ORANGE_WORKER_LOADER_MAX_WEBSOCKET_BUFFER_BYTES to change it, from 1 to 8388608 (8 MiB).The socket closes with code 1011 and the reason ORANGE_WORKER_LOADER_MAX_WEBSOCKET_BUFFER_BYTES exceeded. Orange logs a WorkerLoaderLimitError that names the setting.

    Each running dynamic Worker uses about 54 MiB. Prewarmed VMs that no Worker has claimed do not count toward ORANGE_WORKER_LOADER_MAX_WORKERS, and the limit never stops them.

    Isolation

    • Two dynamic Workers share no filesystem, processes, or loopback.
    • A dynamic Worker shares no globals, module state, process.env, or env with the parent Worker.
    • A dynamic Worker cannot reach the host. node:fs sees only its VM, and it cannot connect to host loopback ports, whatever its globalOutbound.
    • A dynamic Worker with the default globalOutbound gets a VM with network access. With globalOutbound: null or a Fetcher, its VM has no network.

    Lifecycle

    • Orange prewarms VMs for each network mode after that mode’s first dynamic Worker loads, so an app without dynamic Workers boots none. A prewarmed VM has its Node.js process started with Orange’s runtime imported. It has seen no Worker code or env.
    • A load takes a prewarmed VM, puts its modules in it, and starts the Worker. If the pool is empty, it waits for the VM that is booting, or boots its own. The pool refills one VM at a time, shortly after the load finishes.
    • A VM that fails to prewarm is reported as a background error, and the next load boots its own VM. Set ORANGE_WORKER_LOADER_POOL_SIZE to 0 to boot every VM on demand.
    • If the VM cannot boot, get() and load() calls fail with the boot error. Orange never falls back to the host.
    • A dynamic Worker is idle when no call to it is in flight, your Worker holds no stub or stream that it returned, no body or stream flows between the two in either direction, no WebSocket between the two is open, and no call from the dynamic Worker to your Worker or its env is in flight. A streamed response body keeps it busy until the body ends, and a WebSocket keeps it busy until it closes. Orange never stops a dynamic Worker that is not idle.
    • Work that the dynamic Worker does on its own, such as ctx.waitUntil() code that runs while no call or stream is open, does not keep it busy. It can stop when it is idle.
    • An idle dynamic Worker stops after the idle timeout, or sooner when the limit of running dynamic Workers needs its slot. Its process exits and its VM is disposed.
    • A load() or unnamed get() Worker also stops when it is idle and the garbage collector has collected its stub and every entrypoint.
    • After a dynamic Worker stops, get() with its name calls getCode again, as Cloudflare can. A stub or entrypoint that you still hold loads the Worker again on its next call, with fresh module state.
    • If a dynamic Worker’s process exits, its pending calls reject, and the next get() with that name loads it again.
    • A dynamic Worker that fails to start, for example because getCode throws, frees its slot at once. Its calls reject with the startup error.
    • A process that does not exit 5 seconds after Orange stops it is logged, and Orange disposes its VM.

    Transport

    • The parent and the dynamic Worker talk Workers RPC over Cap’n Web, framed on the dynamic Worker process’s stdin and stdout.
    • The dynamic Worker’s own stdout output still reaches the parent’s stdout.
    • Reference passing covers env, props, arguments, and results.

    WebSockets

    A WebSocket request passes through your Worker to the dynamic Worker like any other request: return worker.getEntrypoint().fetch(request). The dynamic Worker accepts it in one of two ways.

    • It returns new Response(null, { status: 101, webSocket }) with one end of a WebSocketPair, as on Cloudflare.
    • Its node:http server has an upgrade listener. A GET request with Upgrade: websocket reaches the listener as (request, socket, head), as in Node.js. The server writes its handshake and WebSocket frames to the socket, which is what the ws package does in handleUpgrade(). Without an upgrade listener, the request goes to the request listener.
    import http from "node:http";
    import { httpServerHandler } from "cloudflare:node";
    import { WebSocketServer } from "ws";
    
    const sockets = new WebSocketServer({ noServer: true });
    const server = http.createServer((req, res) => res.end("ok"));
    server.on("upgrade", (req, socket, head) => {
      sockets.handleUpgrade(req, socket, head, (ws) => {
        ws.on("message", (data, isBinary) => ws.send(data, { binary: isBinary }));
      });
    });
    server.listen(8080);
    export default httpServerHandler({ port: 8080 });
    • Text and binary messages pass in both directions, in order. A close passes its code and reason in both directions.
    • The request’s headers and query string reach the dynamic Worker unchanged, except Sec-WebSocket-Extensions. Orange removes it, so the server negotiates no compression.
    • The response headers of the handshake reach the client, including Sec-WebSocket-Protocol.
    • An upgrade listener that answers with another status, such as socket.end("HTTP/1.1 403 Forbidden\r\n\r\n"), fails the client’s upgrade with that response. A listener that ends the socket without an HTTP response fails it with status 500.
    • An open WebSocket keeps the dynamic Worker running, with or without traffic. The idle timeout starts when its last WebSocket closes. A dynamic Worker with an open WebSocket also keeps its slot, so at the limit of running dynamic Workers a new one fails with WorkerLoaderLimitError.
    • If the dynamic Worker’s process exits, every WebSocket to it closes with code 1006, as after a lost connection.
    • The WebSocket API has no backpressure. Each side counts the bytes that the other side has not taken yet, and closes the socket above the limit in Limits. A message larger than the limit closes it too.
    • The dynamic Worker’s process decodes each message in its V8 heap. In a test with the default 128 MiB heap, a 6 MiB message passed, and an 8 MiB message ended the process with a V8 heap error. With vmLimits.heapMb: 1024, an 8 MiB message passed.
    • A 101 response passes only as the result of a call. Inside another value, such as an array of responses, it fails the call.

    Modules

    • Module forms: a string .js module (ES module), { js }, { cjs }, { text }, { data }, { json }, and { wasm } with bytes, as { wasm: ArrayBuffer }.
    • compatibilityDate and mainModule must be strings, and mainModule must name a module in modules. Invalid code throws a TypeError.
    • load() copies the code before it returns, so later changes to the caller’s buffers do not reach the dynamic Worker, and invalid code throws at once.
    • Each VM mounts a host directory read-only at boot. Orange writes the Worker’s modules as written there, and node:fs reads them as /bundle. Orange deletes the directory with the VM. The linked modules that Node.js imports go in the same directory.
    • A text, JSON, Wasm, or data module reads its bytes from /bundle when it is imported, in 4 MiB reads. A text module decodes them as UTF-8, and a JSON module decodes and then parses them. agentOS answers each read with one message of at most 16 MiB, so a module of any size loads.

    Mounts

    mounts is an Orange extension to the code object, so a dynamic Worker can run a directory of files, such as a Next.js standalone build, without one module per file:

    env.LOADER.get("next", () => ({
      compatibilityDate: "2026-01-01",
      mainModule: "worker.js",
      modules: { "worker.js": workerCode },
      mounts: [
        { guestPath: "/app", hostPath: "app/.next/standalone" }, // read-only
        { guestPath: "/app/.next/cache" }, // empty and writable
      ],
    }));
    • Only the parent Worker’s code callback sets mounts. The dynamic Worker has no API for it.
    • hostPath resolves against the project directory. Its real path, after symlinks, must be a directory inside the project. A hostPath mount is always read-only, and a guest write to it fails.
    • A mount without hostPath is an empty host directory that Orange deletes with the VM.
    • guestPath must be absolute, not /, unique, and outside /open-orange, which Orange reserves.
    • A mount that breaks a rule fails the load with a TypeError that names it.
    • orange deploy does not ship mounted directories yet.

    VM limits

    vmLimits is an Orange extension to the code object. It gives one dynamic Worker’s VM more than the agentOS defaults (a 128 MiB V8 heap and 30 seconds of CPU time for the Worker’s process), for work such as a bundler or a dev server:

    env.LOADER.get("next-dev", () => ({
      compatibilityDate: "2026-01-01",
      mainModule: "worker.js",
      modules: { "worker.js": workerCode },
      vmLimits: { heapMb: 4096, cpuTimeMs: 30 * 60_000 },
    }));
    • heapMb is the V8 heap of the Worker’s process. cpuTimeMs is the CPU time of that process over its whole life, not per request. An omitted member keeps the agentOS default.
    • Each member is a positive integer, at most the runtime cap in Limits. A member above the cap fails the load with a WorkerLoaderLimitError. Another value or member fails it with a TypeError.
    • Only the parent Worker’s code callback sets vmLimits.
    • A Worker with vmLimits boots its own VM, because agentOS sets limits only when it creates a VM. It does not use the prewarmed pool.
    • Cloudflare’s limits (cpuMs, subRequests) are per request. Orange accepts and ignores them.

    The VM runtime

    • The agentOS VM runs Node.js 22.
    • The agentOS VM embeds V8 13.0, which has Wasm exnref off. Orange turns it on, as in workerd, by setting AGENTOS_V8_WASM_EXNREF=1 for its runtime process unless you set the variable yourself. Set it to 0 to turn exnref off. The value holds for every agentOS VM of the runtime, including agentOS sandboxes.
    • The VM bundle fills missing Web globals from node:stream/web, node:buffer, node:crypto, and node:perf_hooks, builds CompressionStream and DecompressionStream on node:zlib, adds URLPattern from urlpattern-polyfill, and sets navigator.
    • Any other global that the VM lacks becomes a class that throws when constructed.
    • Workerd stream fixes that read Node.js 24 stream internals do not apply in the VM, and dynamic Workers there use the VM’s own WebSocket class.
    • A node:http server that encodes its body itself, with Content-Encoding: gzip or br, as the compression middleware of Next.js and Express does, reaches the client encoded once. Orange decodes the body in the VM, and the runtime applies the Content-Encoding when it sends the response.
    • globalOutbound: null blocks the global fetch() and cloudflare:sockets connect(). The VM with no network also blocks node:net and node:http connections.
    • The VM is disposed when the dynamic Worker process exits or stops, or orange dev stops. Stopping orange dev stops every dynamic Worker process.
    • Each VM mounts the VM bundle read-only at /open-orange/runtime. A write there fails with EROFS.
    • pnpm build emits the VM bundle to dist/runtime/worker-loader-vm/. Without it, the first dynamic Worker fails with OpenOrange cannot find the agentOS Worker Loader bundle. Run `pnpm build`.

    Errors

    CallError
    getDurableObjectClass()NotSupportedError: OpenOrange does not support getDurableObjectClass() on dynamic Workers yet. Keep Durable Object state in the parent Worker and call the dynamic Worker through getEntrypoint().
    connect() on an entrypointNotSupportedError: OpenOrange does not support connect() on a dynamic Worker entrypoint. Use fetch() or RPC methods instead.
    connect() through a Fetcher globalOutboundOpenOrange does not support connect() through a dynamic Worker's globalOutbound fetcher. Use fetch() instead.
    A VM that cannot bootOpenOrange cannot boot the agentOS VM for a dynamic Worker: <message>. Dynamic Workers never run on the host.
    A new dynamic Worker when the limit is reached and none is idleWorkerLoaderLimitError: OpenOrange cannot start another dynamic Worker: <n> are running, none is idle, and the limit is <limit>. Raise ORANGE_WORKER_LOADER_MAX_WORKERS or let calls finish first.
    A WebSocket above the buffer limitClose code 1011 with the reason ORANGE_WORKER_LOADER_MAX_WEBSOCKET_BUFFER_BYTES exceeded, and in the log WorkerLoaderLimitError: A dynamic Worker WebSocket held more than <limit> bytes that its peer had not taken, so OpenOrange closed it. Set ORANGE_WORKER_LOADER_MAX_WEBSOCKET_BUFFER_BYTES to raise the limit.
    vmLimits above the runtime capWorkerLoaderLimitError: Dynamic Worker vmLimits.heapMb is <n>, above the runtime cap of <cap>. Set ORANGE_WORKER_LOADER_MAX_VM_HEAP_MB to raise the cap. (cpuTimeMs names ORANGE_WORKER_LOADER_MAX_VM_CPU_TIME_MS)

    Deviations

    These add to the Compatibility table, the Limits, and the host isolation and unloading in Isolation and Lifecycle.

    • A Worker that fails to load is forgotten, so the next get() with that name calls getCode again. Workerd keeps the failed Worker.
    • Workerd keeps a load() Worker while any stub references it. Orange stops an idle one after the idle timeout even then, and the held stub loads it again with fresh module state.
    • Orange allows dynamic entrypoint stubs and uncalled ctx.exports stubs in props, and RpcTargets and functions in env, where workerd throws DataCloneError.
    • The connect() errors are NotSupportedError-style errors.
    • workerd’s node:http server has no upgrade event. Orange emits it in a dynamic Worker. See WebSockets.

    Conformance

    tests/bindings/worker-loader.test.ts drives a real orange dev over HTTP: fetch and RPC, env and props capabilities, isolation, globalOutbound: null, name caching, syntax errors, process crashes, module types, 20 MiB Wasm and data modules in two Workers in a row, Wasm exception handling with exnref, a node:http server and an Express app in a dynamic Worker, and two bursts of loads larger than the VM pool, the second after the first burst’s Workers stop idle, with each Worker isolated from the others and from the read-only runtime mount. A second orange dev with a limit of 2 and a 1.5-second idle timeout checks that idle Workers stop and load again, that calls longer than the timeout finish, that busy Workers fail a new load with WorkerLoaderLimitError, and that more load() calls than the limit succeed.

    packages/cloudflare-conformance/synthetic/worker-loader-lifetime-test.wd-test runs on workerd first, then on Orange. It checks env and globalOutbound stubs in a request after the one that loaded the Worker, module state across requests, a module named under another module, nested modules of every type, and the entrypoint stub’s shape.

    tests/bindings/worker-loader-large-body.test.ts downloads 5 MiB bodies from a node:http server in a dynamic Worker and checks their length and hash: one res.end(), a stream piped to a response that middleware has wrapped, a body that the server gzipped, and two downloads at the same time.

    tests/bindings/worker-loader-websocket.test.ts opens real WebSockets through the parent Worker, once to a WebSocketPair Worker and once to a node:http server with the ws package: text and binary echo, two sockets to two Workers at the same time, a close code and reason from each side, a Worker process that exits with a socket open, an upgrade that the server refuses with and without an HTTP response, and the subprotocol that the server picks. A second orange dev checks that an open socket without traffic keeps its Worker past the idle timeout, that the Worker stops after the socket closes, and that a message above the buffer limit closes the socket with the limit’s name.

    Recorded results

    Recorded results from the conformance run of 2026-11-10 (Orange ea40348), 1,670 of 1,851 tests passing across every area. Each check is works when every result passed and partial when some did. The full feature matrix is on the compatibility page.

    Worker Loader
    Check Status Results