You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tsx: Limits has no memory bound; a sandboxed bundle can exhaust the host process's memory #760
tsx.Limits (tsx/sandbox.go:24-47) bounds load and call time, stack depth, nodes, timers, requests, body size and storage, but has no bound on the memory a bundle allocates. Inside one call budget a bundle can allocate gigabytes (new Array(1e9).fill(0), string doubling), and the whole app runs out of memory.
Why it matters
tsx/pkg is for code an app downloads, plugins included. Every other resource a plugin can exhaust has a quota; memory is the one that takes the host process down with it, so an app cannot promise its users that a misbehaving plugin only breaks itself.
Proposal
Add a Limits.Memory (bytes) that the runtime enforces: count allocations of large arrays, strings, ArrayBuffers and objects in the goja runtime the bundle owns and stop it with a quota error past the bound, the same way Nodes stops it.
If an exact count is not practical, an approximate one (array length × element size, string length) that catches the common exhaustion patterns is still worth having; document what it does not count.
Acceptance
A bundle that allocates past Limits.Memory stops with a quota error and the host process keeps running.
Status after #802 (merged as 3dd494f): with Limits.Memory set, the sandbox now counts memory where goja's built-ins allocate by size (ArrayBuffer and typed arrays, repeat/padStart/padEnd, String.raw, Array.from, join, fill, sort and the copying array methods, apply/Reflect.apply/Reflect.construct argument lists, JSON.stringify output), checks before allocating, reads each size once, and charges across calls until the memory is collected. Memory is still off by default.
Still not counted, so a bundle written to exhaust memory can still do it within one call's time budget: concat, flat, slice, spreads, replace/replaceAll, string + and template literals (goja's lazy ropes), Blob/TextEncoder copies, and plain objects. For example new Array(1e4).fill(new Array(1e4).fill(0)).flat() allocates about 1.6 GB in one call.
Next steps for this issue: wrap replace, replaceAll, flat, concat, slice and spread the same way, then decide the default for DefaultLimits once the remaining paths are bounded or explicitly accepted.
Activity
fix(tsx): count sandbox memory where built-ins allocate by size
fix(tsx): count sandbox memory where built-ins allocate by size
fix(tsx): count sandbox memory where built-ins allocate by size
houko commentedon Nov 19, 2026
Status after #802 (merged as 3dd494f): with
Limits.Memoryset, the sandbox now counts memory where goja's built-ins allocate by size (ArrayBuffer and typed arrays,repeat/padStart/padEnd,String.raw,Array.from,join,fill,sortand the copying array methods,apply/Reflect.apply/Reflect.constructargument lists,JSON.stringifyoutput), checks before allocating, reads each size once, and charges across calls until the memory is collected.Memoryis still off by default.Still not counted, so a bundle written to exhaust memory can still do it within one call's time budget:
concat,flat,slice, spreads,replace/replaceAll, string+and template literals (goja's lazy ropes),Blob/TextEncodercopies, and plain objects. For examplenew Array(1e4).fill(new Array(1e4).fill(0)).flat()allocates about 1.6 GB in one call.Next steps for this issue: wrap
replace,replaceAll,flat,concat,sliceand spread the same way, then decide the default forDefaultLimitsonce the remaining paths are bounded or explicitly accepted.