Skip to content
Ask
Reference

Resource policy

Bounded resource limits across processes, filesystem, descriptors, modules, syscalls, and preview HTTP streams.

Every bounded value the runtime enforces - byte caps, counts and deadlines - is named once in src/resource-policy.ts. DEFAULT_RESOURCE_POLICY holds exactly the constants the runtime shipped with, so a container booted without resources behaved identically to one booted before the policy existed. The policy changes where a bound is written down. Later changes to a default are deliberate and listed below.

Changed defaults

LimitWasNowWhy
timers.previewHostRequestMs5 s120 sA cold first Next.js compile took up to 26 s (timing); at 5 s an ordinary slow first request became a 503.
timers.previewGuestRequestMs6 s125 sThe service-worker wait for the same head. It must stay longer than the host wait so the host’s 503 arrives while the service worker is still waiting; the margin grows from 1 s to 5 s, so ordering holds with room.
timers.previewLookupMs5 s30 sNext took up to 4.4 s to listen (timing).
modules.sourceBytes8 MiB32 MiBLarge framework chunks (Next’s vendor chunk is 7.8 MB natively) approach the old bound.
preview.moduleSourceBytes8 MiB32 MiBThe service worker serves the same chunks, so it must admit what the module graph admits.
modules.graphBytes32 MiB128 MiBKeeps the 4:1 ratio to the per-module bound: one maximum-size module plus 96 MiB of other framework code.
modules.contextSourceBytes (new)8 MiB32 MiBWas a fixed structural constant; now the policy value, equal to modules.sourceBytes.
preview.responseBytes8 MiB64 MiBNext.js dev serves a 13.26 MB unminified main-app.js, which 8 MiB aborts, so Next never hydrates; real framework dev servers routinely exceed 8 MiB. Memory is bounded separately by the 1 MiB in-flight window (preview.responseWindowBytes), so the total only guards runaway responses.
modules.contextOutputBytes (new)32 MiB128 MiBWas a fixed constant; four times the source bound, the ratio the fixed pair had. The compiler’s reply is the lowered code plus an inline source map, so it can exceed its source.

previewStreamIdleMs (15 s), http.responseBytes (outbound Fetch, still 8 MiB), preview.requestBodyBytes and every other limit are unchanged.

TS
const container = await BrowserContainer.boot({
  resources: { snapshot: { entries: 10 }, http: { responseBytes: 4 * 1024 * 1024 } },
});

Removed keys

timers.channelAckMs (5 s) has been removed. It was a peer-acknowledgement deadline, and every site that used it failed or closed a healthy channel whose peer, a guest or the host page, was merely busy in synchronous code; Node has no such deadline. Its scope narrowed site by site (below) until nothing used it. An override may still name it: resolveResourcePolicy validates the value as before (a positive safe integer; otherwise RangeError/ERR_OUT_OF_RANGE, or TypeError/ERR_INVALID_ARG_TYPE for a non-number) and then ignores it, so a boot configuration written for an earlier runtime keeps working and the resolved policy has no such key. REMOVED_LIMITS in src/resource-policy.ts names it. Raising it used to tolerate longer busy periods; there is now no deadline to raise. This is the first removed key; no earlier key was removed, so there was no precedent to follow.

Changed scope

These entries record how timers.channelAckMs lost its users before its removal.

timers.channelAckMs no longer applies to fork IPC. It used to close a fork channel when the peer had not acknowledged a send, or finished a disconnect, within 5 s. A peer that is merely busy in synchronous code does not answer, and Node never closes a channel for that: messages queue and arrive when the peer’s event loop turns. In next build the export worker’s channel closed this way with ERR_IPC_CHANNEL_CLOSED while the main process was busy. Fork IPC now has no deadline. Memory stays bounded by child.ipcQueuedMessages and child.ipcQueuedBytes, counted until the peer’s event loop reads each message (or delivers it, before its listeners are ready), and a send past either throws E2BIG. Native Node buffers without that bound; the bound is a documented divergence. A dead peer is detected by its termination: the parent’s process record stops the channel when the child exits, is killed or fails, and a parent’s exit removes its children. Overriding it no longer changed fork IPC.

Nor does it apply to worker_threads messages any more. Each postMessage armed a 5 s acknowledgement timer that closed the port when a thread or parent busy in synchronous code did not read the message in time; Node never closes a port for that. The port now has no deadline; child.threadQueuedMessages and child.threadQueuedBytes count messages the peer has not read, and a postMessage past either throws E2BIG. Termination, terminate() and close() end the port.

Child stdin writes no longer use it either. The parent failed a write with ETIMEDOUT when the host had not answered it within 5 s; while the host page was busy in synchronous code that happened to healthy writes, where a native pipe write has no deadline. The host answers every write as soon as it handles it, so the parent now waits for that answer; the child’s exit fails the rest with EPIPE, and the existing child.inputQueueDeliveries and child.inputQueueBytes bounds still fail a write past them with E2BIG.

Thread and child startup no longer use it. fork(), spawn() and new Worker() failed with ETIMEDOUT (“Child startup timed out”, “Thread startup timed out”) when the host had not answered the start request within 5 s, which a host page busy in synchronous code caused; Node has no startup deadline. The host answers every start request with spawned or an error, and its only wait, the kernel attach request, has its own bound (syscall.kernelRequestTimeoutMs), so the parent now waits for that answer.

Module publication no longer uses it either. A process failed an ES module import with ETIMEDOUT (“Module publication timed out”) when the host had not answered the publication within 5 s, which a host page busy in synchronous code caused. The host answers every publication, published or failed, so the process now waits for that answer.

How it is resolved and plumbed

  1. BrowserContainer.boot calls resolveResourcePolicy(overrides). Overrides are a deep partial: any subset of groups, any subset of a group’s keys. Unset keys keep their defaults.
  2. Validation follows Node’s argument-validation conventions, not the runtime error taxonomy, because an invalid override is a caller mistake in a boot option rather than a limit being reached: a wrong shape or an unknown group or key raises TypeError with code: 'ERR_INVALID_ARG_TYPE' (a removed key, listed under “Removed keys”, is validated and ignored instead), and a value that is not a positive safe integer, or exceeds a hard maximum the runtime already enforced, raises RangeError with code: 'ERR_OUT_OF_RANGE'. The message names the rejected path, for example resources.snapshot.entries.
  3. Resolution happens before any Worker is constructed or any service worker is registered, so an invalid override cannot leave a partly started container.
  4. The resolved policy travels on the messages that already exist: the kernel Worker receives it on the ready handshake, every process Worker on its boot message, and the service worker on register (and again on discover, the recovery path after a service-worker restart). Each realm installs it with installResourcePolicy before any guest code runs, and enforcement sites read it with resourceLimits(). The service worker is the exception: it serves several containers at once, so it keeps each container’s policy in its owner record.
  5. Three hard maxima predate the policy and are still enforced: http.responseBytes at most 64 MiB, filesystem.descriptorReadBytes at most 64 MiB, install.unzipBytes at most 256 MiB. The context compiler limits add two: modules.contextSourceBytes at most 256 MiB and modules.contextOutputBytes at most 1 GiB, because the reply length travels in a signed 32-bit header word and the reply buffer reserves its maximum as address space.

Budgets over streamed bodies

Preview HTTP is streamed, so two of its limits are totals rather than buffer sizes: preview.requestBodyBytes and preview.responseBytes. Their defaults are 1 MiB and 64 MiB (the response default was 8 MiB; see Changed defaults) and the failure when one is exceeded, but they have no hard maximum - any positive safe integer is accepted - and they are the only limits that may be marked unbounded:

TS
import { BrowserContainer, UNBOUNDED } from '@inbrowser/node';
const container = await BrowserContainer.boot({
  resources: { preview: { responseBytes: UNBOUNDED, requestBodyBytes: 256 * 1024 * 1024 } },
});

UNBOUNDED is Infinity. resolveResourcePolicy accepts it only for the limits named in UNBOUNDED_LIMITS; for every other limit Infinity is still ERR_OUT_OF_RANGE, because those size a buffer, a queue or a deadline. What bounds memory for a streamed body is the in-flight window: preview.requestWindowBytes and preview.responseWindowBytes are the most body bytes one exchange may have posted and not yet consumed in each direction, and they cannot be unbounded. A window below the 64 KiB transport chunk shrinks the frame to the window. BrowserContainer.previewStreams() reports the peak bytes that were in flight. See Preview HTTP transport.

A page hosting several containers shares one host realm. Host-realm helper modules - the IndexedDB stores, install, execArgv parsing, output-stream observers - read the realm accessor, so those host-side bounds follow the most recently booted container; kernel, process-Worker and preview bounds are per-container and exact.

Outbound HTTP egress policy

BootOptions accepts optional outbound HTTP/HTTPS host controls enforced in src/browser-http.ts (httpAllowedHosts, httpBlockedHosts and grouped httpEgress: { allowedHosts?, blockedHosts? }):

  • Patterns match exact hosts (api.example.com, 127.0.0.1, [::1]), wildcard subdomains (*.example.com, which matches sub.example.com and a.b.example.com but not bare example.com), *, and optional explicit :port suffixes (api.example.com:8443, *.example.com:80). Effective ports default to 80 for http: and 443 for https:. Trailing-dot FQDNs (api.example.com.) normalize to api.example.com, and IPv4-mapped IPv6 literals ([::ffff:127.0.0.1] / [::ffff:7f00:1]) canonicalize to dotted-quad IPv4 in both rule parsing and request matching (src/resource-policy.ts:607, src/resource-policy.ts:863).
  • blockedHosts is evaluated before allowedHosts (deny overrides allow). When allowedHosts is defined, every non-matching host/port is denied; an empty array (allowedHosts: []) denies all outbound guest HTTP/HTTPS requests. When composed across a cross-origin installSandboxHost boundary, intersectHttpEgressPolicies (src/resource-policy.ts:827) unions blockedHosts and requires every target to match both host and client allowedHosts layers.
  • Invalid patterns fail synchronously during BrowserContainer.boot with EINVAL before any Worker or service worker starts (src/resource-policy.ts:742-777, src/index.ts:448-452).
  • Disallowed requests fail in src/browser-http.ts:413, src/browser-http.ts:849 with EACCES (UnsupportedError, kind: 'unsupported') before fetch() hits the network, and result.url is re-validated after fetch() (src/browser-http.ts:440-448), cancelling result.body if the final URL lands on a disallowed origin.
  • Resolved egress rules travel on the container’s boot policy carrier so guest processes, child_process children and worker_threads Workers inherit them automatically. Note that this policy governs Node’s http/https adapter; raw globalThis.fetch inside a Worker remains governed by browser connect-src CSP headers (see threat-model.md).

Deprecated aliases

httpResponseLimit, unzipLimit and descriptorReadLimit remain supported BootOptions and keep their own EINVAL validation and messages. Each maps into the policy - http.responseBytes, install.unzipBytes and filesystem.descriptorReadBytes respectively - and an explicit resources entry wins when both are given. They are deprecated, not removed.

Configurable limits (87)

LimitDefaultEnforced inBounds
syscall.callTimeoutMs5 ssrc/process.ts:125, src/protocol.ts:150Guest wait for one kernel syscall completion before the channel poisons.
syscall.kernelRequestTimeoutMs7 ssrc/index.ts:519Host wait for one kernel RPC reply.
filesystem.descriptorReadBytes32 MiBsrc/process.ts:127, src/fs.ts:206Maximum bytes requested per descriptor read.
filesystem.descriptorWriteBytes32 MiBsrc/fs.ts:247, src/fs.ts:301Maximum bytes accepted per descriptor write, and per whole-file write (writeFile, appendFile) whose payload exceeds one 64 KiB syscall call.
filesystem.fileReadBytes32 MiBsrc/fs.ts:252Maximum bytes for a whole-file read.
filesystem.readStreamHighWaterMarkBytes1 MiBsrc/read-stream.ts:53Largest accepted createReadStream highWaterMark.
filesystem.maxTotalBytes1 GiBsrc/kernel.ts:115, src/kernel.ts:435, src/kernel.ts:1856Aggregate regular-file and symlink payload bytes retained in the in-memory volume across reachable links and open descriptors; over-quota writes, truncates, copies, mounts and restores raise ENOSPC (LimitError) without partial mutations.
filesystem.maxInodes200,000src/kernel.ts:100, src/kernel.ts:434, src/kernel.ts:1852Live files, directories and symlinks in the in-memory volume (including root /); excess creations raise ENOSPC (LimitError).
filesystem.maxOpenDescriptors4,096src/kernel.ts:128, src/kernel.ts:1801Concurrent open volume.fds file descriptors per container; excess opens raise EMFILE (LimitError).
filesystem.processWatchers4,096src/kernel.ts:599Registered watchers per guest process.
filesystem.hostWatchers4,096src/kernel.ts:35Host-side watch subscriptions per container.
filesystem.watchQueueEvents256src/kernel.ts:63Undelivered events queued per host watch subscription.
filesystem.watchQueueBytes1 MiBsrc/kernel.ts:64Queued filename bytes per host watch subscription.
modules.sourceBytes32 MiBsrc/vm-source.ts:11, src/index.ts:1358, src/service-worker.ts:156Bytes per published module source, and per vm compilation unit.
modules.graphBytes128 MiBsrc/index.ts:1359Aggregate published module bytes per process.
modules.countPerProcess2,048src/index.ts:1341Published module URLs per process.
modules.contextSourceMapBytes32 MiBsrc/context-compiler.ts:57Source-map text retained per process for experimental async-context stack positions.
modules.contextSourceBytes32 MiBsrc/context-compiler.ts:162, src/context-compiler-worker.ts:23Source bytes per experimental async-context compilation, checked before and after the loader’s rewriting; over it fails with E2BIG carrying limit/actual. Hard maximum 256 MiB.
modules.contextOutputBytes128 MiBsrc/context-compiler.ts:67, src/context-compiler.ts:154, src/context-compiler-worker.ts:24Compiled bytes (code plus inline source map) the compiler may reply with; the reply buffer’s maximum, grown on demand. Hard maximum 1 GiB.
http.responseBytes8 MiBsrc/process.ts:536, src/process.ts:863, src/browser-http.ts:440Decoded response bytes buffered per outbound Fetch response.
http.headerBytes64 KiBsrc/browser-http.ts:404, src/browser-http.ts:455, src/http-client.ts:169, src/http-client.ts:225, src/http-client.ts:238, src/http-client.ts:265Serialized request or response header bytes per outbound request.
http.clientBodyBytes8 MiBsrc/browser-http.ts:133, src/browser-http.ts:222, src/browser-http.ts:375, src/browser-http.ts:806, src/http-client.ts:135, src/http-client.ts:169, src/http-client.ts:264, src/http-client.ts:281, src/http-client.ts:286, src/http-chunks.ts:38Outbound request body bytes buffered in Fetch mode, and request/response body bytes buffered in socket mode.
http.agentRequests1,024src/browser-agent.ts:124Active plus queued requests per Agent instance.
preview.requestBodyBytes1 MiBsrc/preview-fetch.ts:64, src/preview-fetch.ts:170, src/preview-relay.ts:81Total request body bytes one preview request may stream; may be UNBOUNDED.
preview.responseBytes64 MiBsrc/http.ts:315, src/preview-relay.ts:130, src/preview-fetch.ts:218Total response body bytes one preview response may stream; may be UNBOUNDED.
preview.requestWindowBytes1 MiBsrc/preview-fetch.ts:81, src/preview-relay.ts:50, src/http.ts:457Request body bytes in flight between the service worker and the guest reader.
preview.responseWindowBytes1 MiBsrc/http.ts:458, src/preview-relay.ts:51, src/preview-fetch.ts:85Response body bytes in flight between the guest and the browser’s stream reader.
preview.moduleSourceBytes32 MiBsrc/service-worker.ts:156Module source bytes the service worker will serve.
preview.relaysPerContainer64src/index.ts:829, src/index.ts:841Live WebSocket relays per container.
child.maxProcesses64src/index.ts:1211, src/kernel.ts:1644Concurrent live guest processes and worker_threads Workers per container (including pending admissions); excess spawns raise EAGAIN (LimitError) without leaking Workers, ports or descriptors.
child.outputBytes32 MiBsrc/worker-threads.ts:120, src/child-process.ts:322Child output the parent retains in a piped stdout or stderr, in aggregate; inherited output does not count.
child.inputQueueBytes32 MiBsrc/index.ts:1459Undelivered child stdin bytes queued in the host.
child.inputQueueDeliveries1,024src/index.ts:1458Undelivered child stdin writes queued in the host.
child.stdinChunkBytes32 MiBsrc/index.ts:126, src/index.ts:1209, src/index.ts:139Largest accepted ContainerProcess.stdin chunk.
child.pipeBytes32 MiBsrc/kernel.ts:500Unread bytes buffered per kernel stdin pipe.
child.pendingStdinReads1,024src/stdin.ts:137Concurrent unsatisfied guest stdin reads.
child.terminalInputBytes32 MiBsrc/terminal-input.ts:16, src/terminal-input.ts:40Buffered terminal input bytes per device.
child.terminalLineBytes64 KiBsrc/terminal-input.ts:32Longest accepted single terminal input line in the kernel discipline.
child.readlineLineBytes64 KiBsrc/readline-interface.ts:158Longest accepted single readline input line.
child.captureBytes16 MiBsrc/index.ts:155, src/index.ts:1237, src/output-capture.ts:20Most recent bytes retained per stream by a host process handle for stdout/stderr/stdoutText/stderrText; older bytes are dropped and counted in stdoutTruncatedBytes/stderrTruncatedBytes.
child.outputObserverBytes1 MiBsrc/output-channel.ts:10Buffered bytes per host output-stream observer before it errors.
child.shellWords2,048src/shell.ts:40, src/shell.ts:84, src/shell.ts:93, src/shell.ts:120Words produced by one shell command line.
child.shellScriptBytes64 KiBsrc/shell.ts:30Bytes in one shell command line.
child.execArgvCount256src/exec-argv.ts:7Startup (execArgv) strings per process.
child.execArgvBytes64 KiBsrc/exec-argv.ts:15Aggregate startup (execArgv) bytes per process.
child.randomAllocationBytes32 MiBsrc/crypto-random.ts:20, src/crypto-random.ts:89Bytes per randomBytes/randomFill allocation.
child.comparisonBytes32 MiBsrc/crypto-compare.ts:42Bytes per timingSafeEqual operand.
child.ipcMessageBytes1 MiBsrc/ipc.ts:45, src/ipc.ts:74, src/ipc.ts:230, src/ipc.ts:298Bytes per IPC message.
child.ipcQueuedMessages64src/ipc.ts:46, src/ipc.ts:74, src/ipc.ts:230, src/ipc.ts:298IPC messages per direction the peer has not read (or, before its listeners are ready, delivered); the next send throws E2BIG.
child.ipcQueuedBytes8 MiBsrc/ipc.ts:47, src/ipc.ts:74, src/ipc.ts:230, src/ipc.ts:298IPC bytes per direction the peer has not read (or, before its listeners are ready, delivered); the next send throws E2BIG.
child.ipcGraphNodes4,096src/ipc-codec.ts:96, src/ipc-codec.ts:105Nodes in one advanced-serialization IPC graph.
child.ipcGraphEdges65,536src/ipc-codec.ts:33, src/ipc-codec.ts:105Edges in one advanced-serialization IPC graph.
child.ipcGraphDepth128src/ipc-codec.ts:33Depth of one advanced-serialization IPC graph.
child.ipcArraySlots1,048,576src/ipc-codec.ts:75, src/ipc-codec.ts:148, src/ipc-codec.ts:161Aggregate array slots in one advanced-serialization IPC graph.
child.threadMessageBytes1 MiBsrc/thread-port.ts:82, src/thread-port.ts:20, src/thread-port.ts:57Bytes per worker-thread message.
child.threadQueuedMessages64src/thread-port.ts:83Worker-thread messages per direction the peer has not read; the next postMessage throws E2BIG.
child.threadQueuedBytes8 MiBsrc/thread-port.ts:84Worker-thread bytes per direction the peer has not read; the next postMessage throws E2BIG.
child.threadTransferBytes32 MiBsrc/worker-threads.ts:116Bytes per transferred worker-thread ArrayBuffer.
child.threadCollectionEntries65,536src/thread-clone.ts:72, src/thread-clone.ts:80Entries in one worker-thread Map or Set.
child.threadGraphNodes4,096src/thread-port.ts:24, src/thread-clone.ts:34Nodes in one worker-thread structured-clone graph.
child.threadGraphEdges65,536src/thread-port.ts:18, src/thread-clone.ts:34Edges in one worker-thread structured-clone graph.
child.threadGraphDepth128src/thread-port.ts:18, src/thread-clone.ts:34Depth of one worker-thread structured-clone graph.
snapshot.bytes128 MiBsrc/workspace-store.ts:201, src/workspace-store.ts:233, src/index.ts:255, src/kernel.ts:126, src/kernel.ts:141, src/kernel.ts:151, src/snapshot.ts:79, src/workspace-checkpoint.ts:7Logical filesystem bytes per snapshot or checkpoint.
snapshot.entries100,000src/workspace-store.ts:232, src/index.ts:255, src/kernel.ts:115, src/kernel.ts:140, src/kernel.ts:150, src/snapshot.ts:22, src/workspace-checkpoint.ts:7Entries per snapshot or checkpoint.
snapshot.packageCacheBytes128 MiBsrc/package-cache.ts:66, src/package-cache.ts:131Logical bytes per persisted package cache.
snapshot.packageCacheFiles100,000src/package-cache.ts:55, src/package-cache.ts:125Files per persisted package cache.
snapshot.startupConfigBytes64 KiBsrc/workspace-checkpoint.ts:58Serialized checkpoint startup-configuration bytes.
install.packageBytes256 MiBsrc/install.ts:176Aggregate staged bytes for one install.
install.archiveBytes64 MiBsrc/package-archive.ts:30Bytes per downloaded package archive.
install.gzipBytes32 MiBsrc/gzip.ts:9, src/gzip.ts:31, src/gzip.ts:53Input and output bytes per gzip/gunzip operation.
install.unzipBytes32 MiBsrc/process.ts:905, src/unzip.ts:19Input and output bytes per Unzip decoder.
install.lockedPackages2,048src/install.ts:69Locked package entries installed in one call.
timers.interruptGraceMs250 mssrc/index.ts:1544Grace period between delivering SIGINT and terminating the Worker.
timers.gzipMs7 ssrc/gzip.ts:10, src/gzip.ts:44One gzip/gunzip operation.
timers.storeMs7 ssrc/package-cache-store.ts:7, src/workspace-store.ts:32, src/workspace-store.ts:86, src/snapshot-store.ts:7, src/snapshot-store.ts:38, src/snapshot-store.ts:89, src/package-cache-store.ts:38, src/package-cache-store.ts:89IndexedDB open and transaction deadline.
timers.downloadMs20 ssrc/install.ts:107, src/package-archive.ts:14One package download or archive stream.
timers.contextCompilerMs20 ssrc/context-compiler.ts:14, src/context-compiler.ts:55One experimental browser compilation.
timers.httpRequestMs20 ssrc/browser-http.ts:208, src/browser-http.ts:237, src/browser-http.ts:253, src/browser-http.ts:665, src/browser-http.ts:762, src/http-client.ts:116One outbound browser HTTP request.
timers.cryptoInitMs5 ssrc/crypto-compare.ts:18Guest crypto WASM initialization.
timers.previewLookupMs30 ssrc/index.ts:455, src/preview-bridge.ts:78Host wait for a guest to listen on the previewed port and, in origin mode, for its bridge to become ready.
timers.previewHostRequestMs120 ssrc/preview-relay.ts:67Host wait for a guest response head; request-body progress restarts it.
timers.previewGuestRequestMs125 ssrc/preview-fetch.ts:152Service-worker wait for a response head; request-body progress restarts it.
timers.previewModuleRequestMs5 ssrc/service-worker.ts:148Service-worker wait for a published module source.
timers.previewDiscoverMs500 mssrc/service-worker.ts:107, src/preview-origin-sw.ts:105Service-worker wait for one client to claim a container, or for a bridge to supply a port, after a restart.
timers.serviceTaskMs5 ssrc/index.ts:486, src/index.ts:554, src/index.ts:587Host wait for a service-worker registration step or handshake.
timers.previewSocketIdleMs15 ssrc/socket-relay.ts:18Idle period after which a host preview WebSocket relay is closed.
timers.previewStreamIdleMs15 ssrc/preview-relay.ts:227, src/preview-fetch.ts:106, src/preview-origin-sw.ts:130Service-worker silence after which the host ends a streamed preview exchange (pings at a third of it); also a preview-origin worker’s wait for a host liveness reply.

Context compiler buffer

In experimental async-context mode each process owns a compiler Worker. The request (source, filename and the two bounds) goes by postMessage; only the reply travels through a SharedArrayBuffer. That buffer is growable: new SharedArrayBuffer(8 + 1 MiB, { maxByteLength: 8 + modules.contextOutputBytes }). The compiler Worker calls grow() (to a whole number of MiB) only when a reply needs more, and never past the maximum. The process reads each reply through a view created after the reply arrives, and the compiler writes through a view created after growing, so both sides see the grown length. A reply above contextOutputBytes is not written; the Worker reports its size and the process raises E2BIG. The timeout, termination on timeout and non-reuse of a timed-out compiler are unchanged.

Memory per process: before, an eagerly allocated buffer of 32 MiB plus a header of 8 bytes; now 1 MiB plus the header at start, growing to the largest reply seen (rounded up to a whole MiB). The policy maximum (128 MiB by default) is only the size the engine may let the buffer grow to; this work did not measure committed versus reserved memory for it. Nothing else sized by these limits is eager: module sources are strings, measured when published or served.

Fixed limits

These stay constants in their own modules. A Worker sizes a buffer from one at boot, both peers must agree on one before either can validate a message, or the realm that enforces it never receives a boot message - so an override could only produce a protocol mismatch, not a smaller budget. FIXED_LIMITS in src/resource-policy.ts names the structural ones for discoverability.

LimitValueDeclared inWhy it is fixed
Protocol version4src/protocol.ts:9Host, kernel, process and service worker must agree before any message is trusted.
Syscall payload slot1 MiBsrc/protocol.ts:10Both peers map the same SharedArrayBuffer, sized from it at attach (src/index.ts:1134, src/kernel.ts:651).
Syscall header16 Bsrc/protocol.ts:11Fixes the control-word layout inside that buffer.
Transport chunk64 KiBsrc/kernel.ts:486, 504; src/stdin.ts:49, 95, 154; src/fs.ts:169, 211, 256; src/index.ts:141, 154; src/output-channel.ts:25; src/browser-http.ts:484; src/crypto-random.ts:24; src/preview-stream.ts:14Kernel pipe pages are allocated at this size and both sides slice to it; JSON byte encoding is sized to stay inside the 1 MiB slot.
Preview socket frame and message1 MiBsrc/port-socket.ts:17preview-socket.js runs in the previewed document, which receives no boot message.
Preview socket read slack16 KiBsrc/preview-socket.ts:58Same realm; covers WebSocket framing overhead on top of the frame bound.
Preview socket queued packets1,024src/preview-socket.ts:260Same realm.
Preview socket fragments1,024src/preview-socket.ts:223Same realm.
Preview head-injection hold64 KiBsrc/preview-inject.ts:15Leading document bytes the service worker may hold while it looks for the <head> tag; the injector runs per response and receives no policy.
Socket relay poll interval5 ssrc/socket-relay.ts:20A sampling rate, not a resource bound; the idle bound it samples is timers.previewSocketIdleMs.
Preview socket heartbeat5 s ping, 15 s without a pongsrc/port-socket.ts:50, 53Page side only; the host relay answers, so a busy guest cannot trip it.
Preview socket closing handshake5 ssrc/preview-socket.ts:303Armed once the guest has read the page’s close frame, so a busy guest cannot trip it.
Snapshot path depth and length256 components, 4 KiBsrc/snapshot.ts:48Snapshot format shape; the host and kernel parse the same bytes.
Snapshot symlink target8 KiBsrc/snapshot.ts:62Snapshot format shape.
Persistence key name256 Bsrc/snapshot-store.ts:13; src/package-cache-store.ts:13IndexedDB key shape, independent of any budget.
HTTP header policy shape64 origins, 64 names, 256 B per namesrc/http-header-policy.ts:7, 29, 32Bounds a boot option’s own shape, validated identically on the host and in each process Worker.
HTTP egress policy shape1,024 patterns per list, 512 B per patternsrc/resource-policy.ts:615, src/resource-policy.ts:741Bounds httpAllowedHosts / httpBlockedHosts / httpEgress list sizes and pattern lengths.
Sandbox parent origin allowlist64 originssrc/sandbox-host.ts:46Bounds installSandboxHost({ allowedParentOrigins }) list length.
Preview upgrade request shape8 KiB URL, 1 KiB protocols, 256 B hostsrc/index.ts:818, 822, 825WebSocket handshake shape agreed with the service worker.
Chunk decoder seed buffer4 KiBsrc/http-chunks.ts:11A growth seed inside http.clientBodyBytes, not a bound.
VM source label4 KiBsrc/vm-source.ts:27Label shape, matched against pinned Node behavior.
Descriptor alias rangeMAX_SAFE_INTEGER - 3src/kernel.ts:568Exhaustion of the integer space itself.
Host readiness poll interval10 mssrc/index.ts:460, 557A sampling rate inside timers.previewLookupMs and timers.serviceTaskMs.
Preview bridge port issues256 per bridgesrc/preview-bridge-protocol.ts:21Per-origin preview: bounds port reissues to a preview origin that keeps asking; not a budget an embedder tunes.
Preview bridge close wait1 ssrc/preview-bridge-protocol.ts:23Teardown’s wait for a bridge to unregister its worker; the iframe is removed either way.

Deliberately unbounded

Listed in the threat model: CPU and heap per guest process, the virtual listener registry (listen), containers per page, total IndexedDB footprint, and the rate of raw globalThis.fetch calls from guest code outside Node’s http/https adapter. child.maxProcesses bounds concurrent guest Workers per container, and filesystem.maxTotalBytes, filesystem.maxInodes and filesystem.maxOpenDescriptors bound the in-memory volume, while CPU and V8 heap scheduling remain owned by the browser.

Tests

  • tests/unit/resource-policy.unit.test.ts - defaults equal the table above, override validation, alias mapping, deep-partial merge, kernel/process quota defaults, outbound HTTP egress validation/matching/redirect re-validation, and the unbounded marker: accepted for the two preview totals only.
  • tests/resource-quotas.spec.ts - end-to-end enforcement and consistency across child.maxProcesses (EAGAIN), filesystem.maxTotalBytes and filesystem.maxInodes (ENOSPC without partial mutations across writes, truncates, symlinks, hard links, renames, cpSync, mount and restore), filesystem.maxOpenDescriptors (EMFILE), and outbound HTTP egress policy (EACCES across exact hosts, wildcards, ports, child processes and worker threads).
  • tests/sandbox-isolation.spec.ts - cross-origin installSandboxHost and SandboxContainer.boot isolation (cookies, DOM, localStorage, IndexedDB), Worker script Content-Security-Policy headers, LimitError revival across MessagePort, and host-pinned bootOptions precedence.
  • tests/unit/preview-stream.unit.test.ts - window arithmetic and framing.
  • tests/preview-streaming.spec.ts - raised and unbounded preview totals, both windows asserted against previewStreams(), and overflow of each total.
  • tests/resource-policy.spec.ts - a lowered bound raises the same LimitError/code as the default bound, an invalid override is rejected before any Worker starts, and a deprecated alias behaves like the modern spelling.
  • tests/unit/context-compiler-buffer.unit.test.ts - growable reply buffer (starts small, grows in MiB, length-tracking views) and the LimitError limit/actual of the context compiler errors.
  • tests/context-compiler-growth.spec.ts - the buffer is growable, starts at 1 MiB and grows to compile a 12 MiB module; configured source and reply bounds raise E2BIG naming the policy value.
  • tests/preview-slow-head.spec.ts - a first response head after 6.5 s succeeds under the default policy.
  • tests/fs-large-read.spec.ts and tests/browser-http-large.spec.ts assert the descriptorReadLimit and httpResponseLimit aliases match resources.filesystem.descriptorReadBytes and resources.http.responseBytes.