Resource policy
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
| Limit | Was | Now | Why |
|---|---|---|---|
timers.previewHostRequestMs | 5 s | 120 s | A cold first Next.js compile took up to 26 s (timing); at 5 s an ordinary slow first request became a 503. |
timers.previewGuestRequestMs | 6 s | 125 s | The 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.previewLookupMs | 5 s | 30 s | Next took up to 4.4 s to listen (timing). |
modules.sourceBytes | 8 MiB | 32 MiB | Large framework chunks (Next’s vendor chunk is 7.8 MB natively) approach the old bound. |
preview.moduleSourceBytes | 8 MiB | 32 MiB | The service worker serves the same chunks, so it must admit what the module graph admits. |
modules.graphBytes | 32 MiB | 128 MiB | Keeps the 4:1 ratio to the per-module bound: one maximum-size module plus 96 MiB of other framework code. |
modules.contextSourceBytes (new) | 8 MiB | 32 MiB | Was a fixed structural constant; now the policy value, equal to modules.sourceBytes. |
preview.responseBytes | 8 MiB | 64 MiB | Next.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 MiB | 128 MiB | Was 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.
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
BrowserContainer.bootcallsresolveResourcePolicy(overrides). Overrides are a deep partial: any subset of groups, any subset of a group’s keys. Unset keys keep their defaults.- 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
TypeErrorwithcode: '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, raisesRangeErrorwithcode: 'ERR_OUT_OF_RANGE'. The message names the rejected path, for exampleresources.snapshot.entries. - Resolution happens before any Worker is constructed or any service worker is registered, so an invalid override cannot leave a partly started container.
- The resolved policy travels on the messages that already exist: the kernel
Worker receives it on the
readyhandshake, every process Worker on itsbootmessage, and the service worker onregister(and again ondiscover, the recovery path after a service-worker restart). Each realm installs it withinstallResourcePolicybefore any guest code runs, and enforcement sites read it withresourceLimits(). The service worker is the exception: it serves several containers at once, so it keeps each container’s policy in its owner record. - Three hard maxima predate the policy and are still enforced:
http.responseBytesat most 64 MiB,filesystem.descriptorReadBytesat most 64 MiB,install.unzipBytesat most 256 MiB. The context compiler limits add two:modules.contextSourceBytesat most 256 MiB andmodules.contextOutputBytesat 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:
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 matchessub.example.comanda.b.example.combut not bareexample.com),*, and optional explicit:portsuffixes (api.example.com:8443,*.example.com:80). Effective ports default to80forhttp:and443forhttps:. Trailing-dot FQDNs (api.example.com.) normalize toapi.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). blockedHostsis evaluated beforeallowedHosts(deny overrides allow). WhenallowedHostsis defined, every non-matching host/port is denied; an empty array (allowedHosts: []) denies all outbound guest HTTP/HTTPS requests. When composed across a cross-origininstallSandboxHostboundary,intersectHttpEgressPolicies(src/resource-policy.ts:827) unionsblockedHostsand requires every target to match both host and clientallowedHostslayers.- Invalid patterns fail synchronously during
BrowserContainer.bootwithEINVALbefore 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:849withEACCES(UnsupportedError,kind: 'unsupported') beforefetch()hits the network, andresult.urlis re-validated afterfetch()(src/browser-http.ts:440-448), cancellingresult.bodyif the final URL lands on a disallowed origin. - Resolved egress rules travel on the container’s boot policy carrier so guest
processes,
child_processchildren andworker_threadsWorkers inherit them automatically. Note that this policy governs Node’shttp/httpsadapter; rawglobalThis.fetchinside a Worker remains governed by browserconnect-srcCSP 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)
| Limit | Default | Enforced in | Bounds |
|---|---|---|---|
syscall.callTimeoutMs | 5 s | src/process.ts:125, src/protocol.ts:150 | Guest wait for one kernel syscall completion before the channel poisons. |
syscall.kernelRequestTimeoutMs | 7 s | src/index.ts:519 | Host wait for one kernel RPC reply. |
filesystem.descriptorReadBytes | 32 MiB | src/process.ts:127, src/fs.ts:206 | Maximum bytes requested per descriptor read. |
filesystem.descriptorWriteBytes | 32 MiB | src/fs.ts:247, src/fs.ts:301 | Maximum bytes accepted per descriptor write, and per whole-file write (writeFile, appendFile) whose payload exceeds one 64 KiB syscall call. |
filesystem.fileReadBytes | 32 MiB | src/fs.ts:252 | Maximum bytes for a whole-file read. |
filesystem.readStreamHighWaterMarkBytes | 1 MiB | src/read-stream.ts:53 | Largest accepted createReadStream highWaterMark. |
filesystem.maxTotalBytes | 1 GiB | src/kernel.ts:115, src/kernel.ts:435, src/kernel.ts:1856 | Aggregate 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.maxInodes | 200,000 | src/kernel.ts:100, src/kernel.ts:434, src/kernel.ts:1852 | Live files, directories and symlinks in the in-memory volume (including root /); excess creations raise ENOSPC (LimitError). |
filesystem.maxOpenDescriptors | 4,096 | src/kernel.ts:128, src/kernel.ts:1801 | Concurrent open volume.fds file descriptors per container; excess opens raise EMFILE (LimitError). |
filesystem.processWatchers | 4,096 | src/kernel.ts:599 | Registered watchers per guest process. |
filesystem.hostWatchers | 4,096 | src/kernel.ts:35 | Host-side watch subscriptions per container. |
filesystem.watchQueueEvents | 256 | src/kernel.ts:63 | Undelivered events queued per host watch subscription. |
filesystem.watchQueueBytes | 1 MiB | src/kernel.ts:64 | Queued filename bytes per host watch subscription. |
modules.sourceBytes | 32 MiB | src/vm-source.ts:11, src/index.ts:1358, src/service-worker.ts:156 | Bytes per published module source, and per vm compilation unit. |
modules.graphBytes | 128 MiB | src/index.ts:1359 | Aggregate published module bytes per process. |
modules.countPerProcess | 2,048 | src/index.ts:1341 | Published module URLs per process. |
modules.contextSourceMapBytes | 32 MiB | src/context-compiler.ts:57 | Source-map text retained per process for experimental async-context stack positions. |
modules.contextSourceBytes | 32 MiB | src/context-compiler.ts:162, src/context-compiler-worker.ts:23 | Source 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.contextOutputBytes | 128 MiB | src/context-compiler.ts:67, src/context-compiler.ts:154, src/context-compiler-worker.ts:24 | Compiled bytes (code plus inline source map) the compiler may reply with; the reply buffer’s maximum, grown on demand. Hard maximum 1 GiB. |
http.responseBytes | 8 MiB | src/process.ts:536, src/process.ts:863, src/browser-http.ts:440 | Decoded response bytes buffered per outbound Fetch response. |
http.headerBytes | 64 KiB | src/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:265 | Serialized request or response header bytes per outbound request. |
http.clientBodyBytes | 8 MiB | src/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:38 | Outbound request body bytes buffered in Fetch mode, and request/response body bytes buffered in socket mode. |
http.agentRequests | 1,024 | src/browser-agent.ts:124 | Active plus queued requests per Agent instance. |
preview.requestBodyBytes | 1 MiB | src/preview-fetch.ts:64, src/preview-fetch.ts:170, src/preview-relay.ts:81 | Total request body bytes one preview request may stream; may be UNBOUNDED. |
preview.responseBytes | 64 MiB | src/http.ts:315, src/preview-relay.ts:130, src/preview-fetch.ts:218 | Total response body bytes one preview response may stream; may be UNBOUNDED. |
preview.requestWindowBytes | 1 MiB | src/preview-fetch.ts:81, src/preview-relay.ts:50, src/http.ts:457 | Request body bytes in flight between the service worker and the guest reader. |
preview.responseWindowBytes | 1 MiB | src/http.ts:458, src/preview-relay.ts:51, src/preview-fetch.ts:85 | Response body bytes in flight between the guest and the browser’s stream reader. |
preview.moduleSourceBytes | 32 MiB | src/service-worker.ts:156 | Module source bytes the service worker will serve. |
preview.relaysPerContainer | 64 | src/index.ts:829, src/index.ts:841 | Live WebSocket relays per container. |
child.maxProcesses | 64 | src/index.ts:1211, src/kernel.ts:1644 | Concurrent live guest processes and worker_threads Workers per container (including pending admissions); excess spawns raise EAGAIN (LimitError) without leaking Workers, ports or descriptors. |
child.outputBytes | 32 MiB | src/worker-threads.ts:120, src/child-process.ts:322 | Child output the parent retains in a piped stdout or stderr, in aggregate; inherited output does not count. |
child.inputQueueBytes | 32 MiB | src/index.ts:1459 | Undelivered child stdin bytes queued in the host. |
child.inputQueueDeliveries | 1,024 | src/index.ts:1458 | Undelivered child stdin writes queued in the host. |
child.stdinChunkBytes | 32 MiB | src/index.ts:126, src/index.ts:1209, src/index.ts:139 | Largest accepted ContainerProcess.stdin chunk. |
child.pipeBytes | 32 MiB | src/kernel.ts:500 | Unread bytes buffered per kernel stdin pipe. |
child.pendingStdinReads | 1,024 | src/stdin.ts:137 | Concurrent unsatisfied guest stdin reads. |
child.terminalInputBytes | 32 MiB | src/terminal-input.ts:16, src/terminal-input.ts:40 | Buffered terminal input bytes per device. |
child.terminalLineBytes | 64 KiB | src/terminal-input.ts:32 | Longest accepted single terminal input line in the kernel discipline. |
child.readlineLineBytes | 64 KiB | src/readline-interface.ts:158 | Longest accepted single readline input line. |
child.captureBytes | 16 MiB | src/index.ts:155, src/index.ts:1237, src/output-capture.ts:20 | Most 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.outputObserverBytes | 1 MiB | src/output-channel.ts:10 | Buffered bytes per host output-stream observer before it errors. |
child.shellWords | 2,048 | src/shell.ts:40, src/shell.ts:84, src/shell.ts:93, src/shell.ts:120 | Words produced by one shell command line. |
child.shellScriptBytes | 64 KiB | src/shell.ts:30 | Bytes in one shell command line. |
child.execArgvCount | 256 | src/exec-argv.ts:7 | Startup (execArgv) strings per process. |
child.execArgvBytes | 64 KiB | src/exec-argv.ts:15 | Aggregate startup (execArgv) bytes per process. |
child.randomAllocationBytes | 32 MiB | src/crypto-random.ts:20, src/crypto-random.ts:89 | Bytes per randomBytes/randomFill allocation. |
child.comparisonBytes | 32 MiB | src/crypto-compare.ts:42 | Bytes per timingSafeEqual operand. |
child.ipcMessageBytes | 1 MiB | src/ipc.ts:45, src/ipc.ts:74, src/ipc.ts:230, src/ipc.ts:298 | Bytes per IPC message. |
child.ipcQueuedMessages | 64 | src/ipc.ts:46, src/ipc.ts:74, src/ipc.ts:230, src/ipc.ts:298 | IPC messages per direction the peer has not read (or, before its listeners are ready, delivered); the next send throws E2BIG. |
child.ipcQueuedBytes | 8 MiB | src/ipc.ts:47, src/ipc.ts:74, src/ipc.ts:230, src/ipc.ts:298 | IPC bytes per direction the peer has not read (or, before its listeners are ready, delivered); the next send throws E2BIG. |
child.ipcGraphNodes | 4,096 | src/ipc-codec.ts:96, src/ipc-codec.ts:105 | Nodes in one advanced-serialization IPC graph. |
child.ipcGraphEdges | 65,536 | src/ipc-codec.ts:33, src/ipc-codec.ts:105 | Edges in one advanced-serialization IPC graph. |
child.ipcGraphDepth | 128 | src/ipc-codec.ts:33 | Depth of one advanced-serialization IPC graph. |
child.ipcArraySlots | 1,048,576 | src/ipc-codec.ts:75, src/ipc-codec.ts:148, src/ipc-codec.ts:161 | Aggregate array slots in one advanced-serialization IPC graph. |
child.threadMessageBytes | 1 MiB | src/thread-port.ts:82, src/thread-port.ts:20, src/thread-port.ts:57 | Bytes per worker-thread message. |
child.threadQueuedMessages | 64 | src/thread-port.ts:83 | Worker-thread messages per direction the peer has not read; the next postMessage throws E2BIG. |
child.threadQueuedBytes | 8 MiB | src/thread-port.ts:84 | Worker-thread bytes per direction the peer has not read; the next postMessage throws E2BIG. |
child.threadTransferBytes | 32 MiB | src/worker-threads.ts:116 | Bytes per transferred worker-thread ArrayBuffer. |
child.threadCollectionEntries | 65,536 | src/thread-clone.ts:72, src/thread-clone.ts:80 | Entries in one worker-thread Map or Set. |
child.threadGraphNodes | 4,096 | src/thread-port.ts:24, src/thread-clone.ts:34 | Nodes in one worker-thread structured-clone graph. |
child.threadGraphEdges | 65,536 | src/thread-port.ts:18, src/thread-clone.ts:34 | Edges in one worker-thread structured-clone graph. |
child.threadGraphDepth | 128 | src/thread-port.ts:18, src/thread-clone.ts:34 | Depth of one worker-thread structured-clone graph. |
snapshot.bytes | 128 MiB | src/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:7 | Logical filesystem bytes per snapshot or checkpoint. |
snapshot.entries | 100,000 | src/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:7 | Entries per snapshot or checkpoint. |
snapshot.packageCacheBytes | 128 MiB | src/package-cache.ts:66, src/package-cache.ts:131 | Logical bytes per persisted package cache. |
snapshot.packageCacheFiles | 100,000 | src/package-cache.ts:55, src/package-cache.ts:125 | Files per persisted package cache. |
snapshot.startupConfigBytes | 64 KiB | src/workspace-checkpoint.ts:58 | Serialized checkpoint startup-configuration bytes. |
install.packageBytes | 256 MiB | src/install.ts:176 | Aggregate staged bytes for one install. |
install.archiveBytes | 64 MiB | src/package-archive.ts:30 | Bytes per downloaded package archive. |
install.gzipBytes | 32 MiB | src/gzip.ts:9, src/gzip.ts:31, src/gzip.ts:53 | Input and output bytes per gzip/gunzip operation. |
install.unzipBytes | 32 MiB | src/process.ts:905, src/unzip.ts:19 | Input and output bytes per Unzip decoder. |
install.lockedPackages | 2,048 | src/install.ts:69 | Locked package entries installed in one call. |
timers.interruptGraceMs | 250 ms | src/index.ts:1544 | Grace period between delivering SIGINT and terminating the Worker. |
timers.gzipMs | 7 s | src/gzip.ts:10, src/gzip.ts:44 | One gzip/gunzip operation. |
timers.storeMs | 7 s | src/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:89 | IndexedDB open and transaction deadline. |
timers.downloadMs | 20 s | src/install.ts:107, src/package-archive.ts:14 | One package download or archive stream. |
timers.contextCompilerMs | 20 s | src/context-compiler.ts:14, src/context-compiler.ts:55 | One experimental browser compilation. |
timers.httpRequestMs | 20 s | src/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:116 | One outbound browser HTTP request. |
timers.cryptoInitMs | 5 s | src/crypto-compare.ts:18 | Guest crypto WASM initialization. |
timers.previewLookupMs | 30 s | src/index.ts:455, src/preview-bridge.ts:78 | Host wait for a guest to listen on the previewed port and, in origin mode, for its bridge to become ready. |
timers.previewHostRequestMs | 120 s | src/preview-relay.ts:67 | Host wait for a guest response head; request-body progress restarts it. |
timers.previewGuestRequestMs | 125 s | src/preview-fetch.ts:152 | Service-worker wait for a response head; request-body progress restarts it. |
timers.previewModuleRequestMs | 5 s | src/service-worker.ts:148 | Service-worker wait for a published module source. |
timers.previewDiscoverMs | 500 ms | src/service-worker.ts:107, src/preview-origin-sw.ts:105 | Service-worker wait for one client to claim a container, or for a bridge to supply a port, after a restart. |
timers.serviceTaskMs | 5 s | src/index.ts:486, src/index.ts:554, src/index.ts:587 | Host wait for a service-worker registration step or handshake. |
timers.previewSocketIdleMs | 15 s | src/socket-relay.ts:18 | Idle period after which a host preview WebSocket relay is closed. |
timers.previewStreamIdleMs | 15 s | src/preview-relay.ts:227, src/preview-fetch.ts:106, src/preview-origin-sw.ts:130 | Service-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.
| Limit | Value | Declared in | Why it is fixed |
|---|---|---|---|
| Protocol version | 4 | src/protocol.ts:9 | Host, kernel, process and service worker must agree before any message is trusted. |
| Syscall payload slot | 1 MiB | src/protocol.ts:10 | Both peers map the same SharedArrayBuffer, sized from it at attach (src/index.ts:1134, src/kernel.ts:651). |
| Syscall header | 16 B | src/protocol.ts:11 | Fixes the control-word layout inside that buffer. |
| Transport chunk | 64 KiB | src/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:14 | Kernel 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 message | 1 MiB | src/port-socket.ts:17 | preview-socket.js runs in the previewed document, which receives no boot message. |
| Preview socket read slack | 16 KiB | src/preview-socket.ts:58 | Same realm; covers WebSocket framing overhead on top of the frame bound. |
| Preview socket queued packets | 1,024 | src/preview-socket.ts:260 | Same realm. |
| Preview socket fragments | 1,024 | src/preview-socket.ts:223 | Same realm. |
| Preview head-injection hold | 64 KiB | src/preview-inject.ts:15 | Leading 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 interval | 5 s | src/socket-relay.ts:20 | A sampling rate, not a resource bound; the idle bound it samples is timers.previewSocketIdleMs. |
| Preview socket heartbeat | 5 s ping, 15 s without a pong | src/port-socket.ts:50, 53 | Page side only; the host relay answers, so a busy guest cannot trip it. |
| Preview socket closing handshake | 5 s | src/preview-socket.ts:303 | Armed once the guest has read the page’s close frame, so a busy guest cannot trip it. |
| Snapshot path depth and length | 256 components, 4 KiB | src/snapshot.ts:48 | Snapshot format shape; the host and kernel parse the same bytes. |
| Snapshot symlink target | 8 KiB | src/snapshot.ts:62 | Snapshot format shape. |
| Persistence key name | 256 B | src/snapshot-store.ts:13; src/package-cache-store.ts:13 | IndexedDB key shape, independent of any budget. |
| HTTP header policy shape | 64 origins, 64 names, 256 B per name | src/http-header-policy.ts:7, 29, 32 | Bounds a boot option’s own shape, validated identically on the host and in each process Worker. |
| HTTP egress policy shape | 1,024 patterns per list, 512 B per pattern | src/resource-policy.ts:615, src/resource-policy.ts:741 | Bounds httpAllowedHosts / httpBlockedHosts / httpEgress list sizes and pattern lengths. |
| Sandbox parent origin allowlist | 64 origins | src/sandbox-host.ts:46 | Bounds installSandboxHost({ allowedParentOrigins }) list length. |
| Preview upgrade request shape | 8 KiB URL, 1 KiB protocols, 256 B host | src/index.ts:818, 822, 825 | WebSocket handshake shape agreed with the service worker. |
| Chunk decoder seed buffer | 4 KiB | src/http-chunks.ts:11 | A growth seed inside http.clientBodyBytes, not a bound. |
| VM source label | 4 KiB | src/vm-source.ts:27 | Label shape, matched against pinned Node behavior. |
| Descriptor alias range | MAX_SAFE_INTEGER - 3 | src/kernel.ts:568 | Exhaustion of the integer space itself. |
| Host readiness poll interval | 10 ms | src/index.ts:460, 557 | A sampling rate inside timers.previewLookupMs and timers.serviceTaskMs. |
| Preview bridge port issues | 256 per bridge | src/preview-bridge-protocol.ts:21 | Per-origin preview: bounds port reissues to a preview origin that keeps asking; not a budget an embedder tunes. |
| Preview bridge close wait | 1 s | src/preview-bridge-protocol.ts:23 | Teardown’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 acrosschild.maxProcesses(EAGAIN),filesystem.maxTotalBytesandfilesystem.maxInodes(ENOSPCwithout partial mutations across writes, truncates, symlinks, hard links, renames,cpSync,mountandrestore),filesystem.maxOpenDescriptors(EMFILE), and outbound HTTP egress policy (EACCESacross exact hosts, wildcards, ports, child processes and worker threads).tests/sandbox-isolation.spec.ts- cross-origininstallSandboxHostandSandboxContainer.bootisolation (cookies, DOM,localStorage, IndexedDB), Worker scriptContent-Security-Policyheaders,LimitErrorrevival acrossMessagePort, and host-pinnedbootOptionsprecedence.tests/unit/preview-stream.unit.test.ts- window arithmetic and framing.tests/preview-streaming.spec.ts- raised and unbounded preview totals, both windows asserted againstpreviewStreams(), and overflow of each total.tests/resource-policy.spec.ts- a lowered bound raises the sameLimitError/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 theLimitErrorlimit/actualof 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 raiseE2BIGnaming 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.tsandtests/browser-http-large.spec.tsassert thedescriptorReadLimitandhttpResponseLimitaliases matchresources.filesystem.descriptorReadBytesandresources.http.responseBytes.