@toolpal/sandbox 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,85 @@
1
+ Toolpal License
2
+
3
+ Copyright (c) 2026 the Toolpal authors. All rights reserved.
4
+
5
+ This license covers the Toolpal client packages: toolpal, @toolpal/sdk,
6
+ @toolpal/tool, @toolpal/runtime, @toolpal/sandbox, @toolpal/manifest,
7
+ @toolpal/analyzer and @toolpal/builder (together, the "Software"). It does not
8
+ cover any other Toolpal software or service, such as the Toolpal registry or
9
+ website. The Toolpal authors are the "licensor"; "you" means the person or
10
+ organization using the Software.
11
+
12
+ 1. Use
13
+
14
+ The licensor grants you a free, worldwide, non-exclusive, non-transferable
15
+ license to install, run and use the Software for any purpose, including
16
+ commercial purposes, subject to the terms below.
17
+
18
+ 2. Tools you build
19
+
20
+ You may include @toolpal/tool, and any other code the Software adds to a
21
+ tool when it builds one, in tools you create. You may publish and
22
+ distribute those tools, through the Toolpal registry or otherwise, under
23
+ terms you choose for your own code. The parts of a tool that come from the
24
+ Software remain under this license.
25
+
26
+ 3. Copies
27
+
28
+ You may make the copies of the Software you need to use it, including in
29
+ your own applications, container images, caches and deployments, as long
30
+ as each copy keeps this license and is unmodified apart from automated
31
+ bundling, compilation or minification.
32
+
33
+ 4. Restrictions
34
+
35
+ You may not:
36
+
37
+ a. modify the Software or make derivative works of it, except as
38
+ sections 2 and 3 allow;
39
+ b. sell, rent, lease or sublicense the Software, or distribute it on its
40
+ own, except as sections 2 and 3 allow;
41
+ c. use the Software to offer a product or service that competes with
42
+ Toolpal, such as a tool registry or marketplace, without the
43
+ licensor's written permission;
44
+ d. remove or change any copyright, license or other notice in the
45
+ Software.
46
+
47
+ 5. Third-party software
48
+
49
+ The Software uses open-source components that are licensed to you under
50
+ their own licenses. Nothing in this license limits your rights under
51
+ those licenses.
52
+
53
+ 6. Ownership
54
+
55
+ The licensor keeps all rights in the Software that this license does not
56
+ expressly grant you. This license grants no rights to the Toolpal name or
57
+ logo.
58
+
59
+ 7. Termination
60
+
61
+ This license ends automatically if you break any of its terms. You must
62
+ then stop using the Software and delete your copies of it. Tools you
63
+ distributed before then stay licensed under section 2 for the people who
64
+ received them.
65
+
66
+ 8. No warranty
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
69
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
70
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
71
+
72
+ 9. Limitation of liability
73
+
74
+ IN NO EVENT SHALL THE LICENSOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
75
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
76
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
77
+ DEALINGS IN THE SOFTWARE. THIS INCLUDES HARM CAUSED BY TOOLS YOU RUN WITH
78
+ THE SOFTWARE: ITS ISOLATION REDUCES RISK BUT IS NOT A GUARANTEE (SEE THE
79
+ SECURITY MODEL IN THE TOOLPAL DOCUMENTATION).
80
+
81
+ 10. Future versions
82
+
83
+ The licensor may release future versions of the Software under different
84
+ terms. Each version of the Software is governed by the license included
85
+ with it.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @toolpal/sandbox
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Runs [Toolpal](https://toolpal.dev) workflows inside permission-restricted Node.js child processes (`--permission`, `--no-addons`, isolated temp directories, strict env allowlisting, and memory/timeout limits).
4
+
5
+ Most users should install the [`toolpal`](https://www.npmjs.com/package/toolpal) CLI/SDK instead.
@@ -0,0 +1,318 @@
1
+ // toolpal child runner: the entrypoint of every tool process.
2
+ //
3
+ // It is started as `node --permission --allow-fs-read=<toolDir> ... runner.mjs`.
4
+ // The entrypoint gets implicit read access, but nothing else outside the tool
5
+ // directory does, so this file must stay self-contained: Node built-ins only.
6
+ //
7
+ // Protocol (newline-delimited JSON):
8
+ // parent → child (stdin): {type:"init", entry, entryIntegrity, netMode}
9
+ // {type:"call", id, input, outputDir?}
10
+ // child → parent (stdout): {type:"ready", description, node}
11
+ // {type:"result", id, output} | {type:"error", id, error}
12
+ // {type:"log", id, level, message, data?}
13
+ // {type:"fatal", code, message}
14
+
15
+ import { createHash } from "node:crypto";
16
+ import { readFileSync } from "node:fs";
17
+ import * as nodeModule from "node:module";
18
+ import { pathToFileURL } from "node:url";
19
+ import { inspect } from "node:util";
20
+
21
+ const realWrite = process.stdout.write.bind(process.stdout);
22
+ let currentCallId = null;
23
+ let tool = null;
24
+ let initialized = false;
25
+
26
+ const NET_MODULES = new Set([
27
+ "net",
28
+ "tls",
29
+ "http",
30
+ "https",
31
+ "http2",
32
+ "dgram",
33
+ "dns",
34
+ "dns/promises",
35
+ "quic",
36
+ "_http_agent",
37
+ "_http_client",
38
+ "_http_common",
39
+ "_http_incoming",
40
+ "_http_outgoing",
41
+ "_http_server",
42
+ "_tls_common",
43
+ "_tls_wrap",
44
+ ]);
45
+
46
+ function send(frame) {
47
+ realWrite(`${JSON.stringify(frame)}\n`);
48
+ }
49
+
50
+ function fatal(code, message) {
51
+ realWrite(`${JSON.stringify({ type: "fatal", code, message: String(message) })}\n`, () => {
52
+ process.exit(1);
53
+ });
54
+ }
55
+
56
+ function denied(what) {
57
+ const err = new Error(`toolpal: access to ${what} is denied`);
58
+ err.code = "ERR_ACCESS_DENIED";
59
+ return err;
60
+ }
61
+
62
+ function bareModule(spec) {
63
+ return spec.startsWith("node:") ? spec.slice(5) : spec;
64
+ }
65
+
66
+ function serializeError(err) {
67
+ if (err instanceof Error) {
68
+ return {
69
+ name: err.name,
70
+ message: err.message,
71
+ code: typeof err.code === "string" ? err.code : undefined,
72
+ stack: typeof err.stack === "string" ? err.stack.slice(0, 4096) : undefined,
73
+ };
74
+ }
75
+ return { name: "Error", message: String(err) };
76
+ }
77
+
78
+ function toJsonValue(data) {
79
+ try {
80
+ const json = JSON.stringify(data);
81
+ if (json === undefined || json.length > 16_384)
82
+ return inspect(data, { depth: 3 }).slice(0, 16_384);
83
+ return JSON.parse(json);
84
+ } catch {
85
+ return inspect(data, { depth: 3 }).slice(0, 16_384);
86
+ }
87
+ }
88
+
89
+ function log(level, message, data) {
90
+ const frame = { type: "log", id: currentCallId, level, message: String(message).slice(0, 8192) };
91
+ if (data !== undefined) frame.data = toJsonValue(data);
92
+ send(frame);
93
+ }
94
+
95
+ // ---------------------------------------------------------------------------
96
+ // Network guard (Node 22/24 only, tools without the `net` permission).
97
+ // Node <25 has no --allow-net, so this is best-effort: it locks the JS entry
98
+ // points every socket goes through. Deliberately malicious code may still find
99
+ // a way around it; Node >=25 enforces the same rule natively.
100
+ // ---------------------------------------------------------------------------
101
+
102
+ function lockProperty(target, key, value) {
103
+ try {
104
+ Object.defineProperty(target, key, {
105
+ value,
106
+ writable: false,
107
+ configurable: false,
108
+ enumerable: false,
109
+ });
110
+ } catch {
111
+ // Already non-configurable: leave it; the module/connect locks still apply.
112
+ }
113
+ }
114
+
115
+ function installNetGuard() {
116
+ for (const name of ["fetch", "WebSocket", "EventSource"]) {
117
+ if (name in globalThis) {
118
+ lockProperty(globalThis, name, function blockedNetworkGlobal() {
119
+ throw denied(name);
120
+ });
121
+ }
122
+ }
123
+
124
+ const get = process.getBuiltinModule.bind(process);
125
+ const net = get("node:net");
126
+ for (const proto of [net.Socket.prototype, net.Server.prototype]) {
127
+ for (const method of ["connect", "listen"]) {
128
+ if (typeof proto[method] === "function") {
129
+ lockProperty(proto, method, function blockedSocketMethod() {
130
+ throw denied(`net ${method}()`);
131
+ });
132
+ }
133
+ }
134
+ }
135
+ const dgram = get("node:dgram");
136
+ for (const method of ["bind", "connect", "send", "addMembership"]) {
137
+ lockProperty(dgram.Socket.prototype, method, function blockedUdp() {
138
+ throw denied(`dgram ${method}()`);
139
+ });
140
+ }
141
+ const dns = get("node:dns");
142
+ for (const target of [
143
+ dns,
144
+ dns.promises,
145
+ dns.Resolver.prototype,
146
+ dns.promises.Resolver.prototype,
147
+ ]) {
148
+ for (const key of Object.getOwnPropertyNames(target)) {
149
+ if (
150
+ key !== "constructor" &&
151
+ typeof target[key] === "function" &&
152
+ /^(lookup|resolve|reverse)/.test(key)
153
+ ) {
154
+ lockProperty(target, key, function blockedDns() {
155
+ throw denied(`dns ${key}()`);
156
+ });
157
+ }
158
+ }
159
+ }
160
+
161
+ lockProperty(process, "getBuiltinModule", function guardedGetBuiltinModule(id) {
162
+ if (NET_MODULES.has(bareModule(String(id)))) throw denied(`module "${id}"`);
163
+ return get(id);
164
+ });
165
+ }
166
+
167
+ // ---------------------------------------------------------------------------
168
+ // Module loading: only the verified bundle (and Node built-ins) may load.
169
+ // ---------------------------------------------------------------------------
170
+
171
+ function installModuleHooks(entryUrl, source, guardNetwork) {
172
+ nodeModule.registerHooks({
173
+ resolve(specifier, context, nextResolve) {
174
+ if (nodeModule.isBuiltin(specifier)) {
175
+ if (guardNetwork && NET_MODULES.has(bareModule(specifier)))
176
+ throw denied(`module "${specifier}"`);
177
+ return nextResolve(specifier, context);
178
+ }
179
+ const resolved = nextResolve(specifier, context);
180
+ if (resolved.url === entryUrl) return resolved;
181
+ throw denied(`loading "${specifier}" (only the verified tool bundle may run)`);
182
+ },
183
+ load(url, context, nextLoad) {
184
+ // Serve the bytes that were hashed, so a file swapped on disk after the
185
+ // integrity check can never be the code that runs.
186
+ if (url === entryUrl) return { format: "module", source, shortCircuit: true };
187
+ return nextLoad(url, context);
188
+ },
189
+ });
190
+
191
+ // Tools may not install their own loader hooks on top of ours.
192
+ const cjsModule = process.getBuiltinModule("node:module");
193
+ for (const key of ["register", "registerHooks"]) {
194
+ lockProperty(cjsModule, key, function blockedLoaderApi() {
195
+ throw denied(`module.${key}()`);
196
+ });
197
+ }
198
+ cjsModule.syncBuiltinESMExports();
199
+ }
200
+
201
+ function redirectOutput() {
202
+ const levels = {
203
+ log: "info",
204
+ info: "info",
205
+ warn: "warn",
206
+ error: "error",
207
+ debug: "debug",
208
+ trace: "debug",
209
+ };
210
+ for (const [method, level] of Object.entries(levels)) {
211
+ console[method] = (...args) =>
212
+ log(level, args.map((a) => (typeof a === "string" ? a : inspect(a, { depth: 3 }))).join(" "));
213
+ }
214
+ // Stray writes become log lines instead of corrupting the frame stream.
215
+ process.stdout.write = (chunk, encoding, callback) => {
216
+ log("info", typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8"));
217
+ const cb = typeof encoding === "function" ? encoding : callback;
218
+ if (typeof cb === "function") cb();
219
+ return true;
220
+ };
221
+ }
222
+
223
+ // ---------------------------------------------------------------------------
224
+ // Lifecycle
225
+ // ---------------------------------------------------------------------------
226
+
227
+ async function onInit(frame) {
228
+ const { entry, entryIntegrity, netMode } = frame;
229
+ if (netMode === "guard") installNetGuard();
230
+
231
+ const source = readFileSync(entry);
232
+ const actual = `sha256-${createHash("sha256").update(source).digest("base64")}`;
233
+ if (actual !== entryIntegrity) {
234
+ fatal(
235
+ "INTEGRITY_FAILED",
236
+ `tool bundle hash ${actual} does not match expected ${entryIntegrity}`,
237
+ );
238
+ return;
239
+ }
240
+
241
+ const entryUrl = pathToFileURL(entry).href;
242
+ installModuleHooks(entryUrl, source, netMode === "guard");
243
+ redirectOutput();
244
+
245
+ const mod = await import(entryUrl);
246
+ const candidate = mod.default;
247
+ if (candidate?.__toolpal !== 1 || typeof candidate.handler !== "function") {
248
+ fatal("INVALID_TOOL", "the bundle's default export is not a Toolpal tool (use defineTool())");
249
+ return;
250
+ }
251
+ tool = candidate;
252
+ let description = null;
253
+ try {
254
+ description = typeof tool.describe === "function" ? tool.describe() : null;
255
+ } catch (err) {
256
+ log("warn", `describe() failed: ${err?.message ?? err}`);
257
+ }
258
+ const sdk = typeof tool.sdkVersion === "string" ? tool.sdkVersion : null;
259
+ send({ type: "ready", description, sdk, node: process.versions.node });
260
+ }
261
+
262
+ async function onCall(frame) {
263
+ const { id, input, outputDir } = frame;
264
+ currentCallId = id;
265
+ const ctx = Object.freeze({
266
+ log: (level, message, data) => log(level, message, data),
267
+ get outputDir() {
268
+ if (typeof outputDir === "string") return outputDir;
269
+ throw new Error("ctx.outputDir is only for a tool with a FilePath() field");
270
+ },
271
+ });
272
+ try {
273
+ const output = await tool.handler(input, ctx);
274
+ let json;
275
+ try {
276
+ json = JSON.stringify(output);
277
+ } catch (err) {
278
+ throw new Error(`output is not JSON-serializable: ${err.message}`);
279
+ }
280
+ if (json === undefined) throw new Error("handler returned undefined; return an object");
281
+ realWrite(`{"type":"result","id":${JSON.stringify(id)},"output":${json}}\n`);
282
+ } catch (err) {
283
+ send({ type: "error", id, error: serializeError(err) });
284
+ } finally {
285
+ currentCallId = null;
286
+ }
287
+ }
288
+
289
+ function onFrame(frame) {
290
+ if (frame.type === "init" && !initialized) {
291
+ initialized = true;
292
+ onInit(frame).catch((err) => {
293
+ const code = err?.code === "ERR_ACCESS_DENIED" ? "ACCESS_DENIED" : "TOOL_CRASHED";
294
+ fatal(code, `failed to load tool: ${err?.stack ?? err}`);
295
+ });
296
+ } else if (frame.type === "call" && tool) {
297
+ onCall(frame);
298
+ }
299
+ }
300
+
301
+ function onUnexpected(err) {
302
+ const code = err?.code === "ERR_ACCESS_DENIED" ? "ACCESS_DENIED" : "TOOL_CRASHED";
303
+ fatal(code, err?.stack ?? String(err));
304
+ }
305
+ process.on("uncaughtException", onUnexpected);
306
+ process.on("unhandledRejection", onUnexpected);
307
+
308
+ let buffered = "";
309
+ process.stdin.setEncoding("utf8");
310
+ process.stdin.on("data", (chunk) => {
311
+ buffered += chunk;
312
+ for (let nl = buffered.indexOf("\n"); nl !== -1; nl = buffered.indexOf("\n")) {
313
+ const line = buffered.slice(0, nl);
314
+ buffered = buffered.slice(nl + 1);
315
+ if (line.trim() !== "") onFrame(JSON.parse(line));
316
+ }
317
+ });
318
+ process.stdin.on("end", () => process.exit(0));
@@ -0,0 +1,7 @@
1
+ export type SandboxErrorCode = "TIMEOUT" | "ABORTED" | "OUT_OF_MEMORY" | "TOOL_CRASHED" | "TOOL_ERROR" | "ACCESS_DENIED" | "OUTPUT_TOO_LARGE" | "PROTOCOL_ERROR" | "INTEGRITY_FAILED" | "INVALID_TOOL" | "UNSUPPORTED_NODE" | "SPAWN_FAILED";
2
+ export declare class SandboxError extends Error {
3
+ readonly code: SandboxErrorCode;
4
+ readonly details: Record<string, unknown>;
5
+ constructor(code: SandboxErrorCode, message: string, details?: Record<string, unknown>);
6
+ }
7
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,SAAS,GACT,eAAe,GACf,cAAc,GACd,YAAY,GACZ,eAAe,GACf,kBAAkB,GAClB,gBAAgB,GAChB,kBAAkB,GAClB,cAAc,GACd,kBAAkB,GAClB,cAAc,CAAC;AAEnB,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE1C,YAAY,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAKzF;CACF"}
package/dist/errors.js ADDED
@@ -0,0 +1,11 @@
1
+ export class SandboxError extends Error {
2
+ code;
3
+ details;
4
+ constructor(code, message, details = {}) {
5
+ super(message);
6
+ this.name = "SandboxError";
7
+ this.code = code;
8
+ this.details = details;
9
+ }
10
+ }
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAcA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAmB;IACvB,OAAO,CAA0B;IAE1C,YAAY,IAAsB,EAAE,OAAe,EAAE,OAAO,GAA4B,EAAE;QACxF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export { SandboxError, type SandboxErrorCode } from "./errors.js";
2
+ export { END_OF_LIFE_MAJORS, NODE_ADVISORIES, type NodeAdvisory, nodeAdvisoriesFor, } from "./node-advisories.js";
3
+ export { compareVersions, type NodeRuntime, parseVersion, resolveNodeRuntime, } from "./node-version.js";
4
+ export { RUNNER_PATH } from "./runner-path.js";
5
+ export { type CallFiles, type RunOptions, type RunResult, type RunSpec, Supervisor, type SupervisorOptions, } from "./supervisor.js";
6
+ export { buildChildEnv, buildNodeArgs, type CallDirs, type CallOptions, type LogEntry, type LogHandler, type SpawnSpec, type ToolDescription, type ToolExampleInput, } from "./tool-process.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,KAAK,YAAY,EACjB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,KAAK,WAAW,EAChB,YAAY,EACZ,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,UAAU,EACV,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,aAAa,EACb,aAAa,EACb,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { SandboxError } from "./errors.js";
2
+ export { END_OF_LIFE_MAJORS, NODE_ADVISORIES, nodeAdvisoriesFor, } from "./node-advisories.js";
3
+ export { compareVersions, parseVersion, resolveNodeRuntime, } from "./node-version.js";
4
+ export { RUNNER_PATH } from "./runner-path.js";
5
+ export { Supervisor, } from "./supervisor.js";
6
+ export { buildChildEnv, buildNodeArgs, } from "./tool-process.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,aAAa,CAAC;AAClE,OAAO,EACL,kBAAkB,EAClB,eAAe,EAEf,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EAEf,YAAY,EACZ,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAKL,UAAU,GAEX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,aAAa,EACb,aAAa,GAQd,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Known Node.js permission-model bypasses and the first fixed release per major.
3
+ * Update with every Node.js security release. Sources: nodejs.org security
4
+ * blog (Jan 13 2026 release) and the per-CVE advisories.
5
+ */
6
+ export interface NodeAdvisory {
7
+ cve: string;
8
+ summary: string;
9
+ /** major → first patched version on that line. */
10
+ fixed: Readonly<Record<number, string>>;
11
+ }
12
+ export declare const NODE_ADVISORIES: readonly NodeAdvisory[];
13
+ /** Release lines that no longer receive security fixes. */
14
+ export declare const END_OF_LIFE_MAJORS: ReadonlySet<number>;
15
+ /** Warnings for a Node version used to run tools; empty when fully patched. */
16
+ export declare function nodeAdvisoriesFor(version: string): string[];
17
+ //# sourceMappingURL=node-advisories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-advisories.d.ts","sourceRoot":"","sources":["../src/node-advisories.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACzC;AAED,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAqBlD,CAAC;AAEF,2DAA2D;AAC3D,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAA6B,CAAC;AAEjF,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAe3D"}
@@ -0,0 +1,41 @@
1
+ import { compareVersions, parseVersion } from "./node-version.js";
2
+ export const NODE_ADVISORIES = [
3
+ {
4
+ cve: "CVE-2025-55130",
5
+ summary: "crafted symlink paths escape --allow-fs-read/--allow-fs-write",
6
+ fixed: { 20: "20.20.0", 22: "22.22.0", 24: "24.13.0", 25: "25.3.0" },
7
+ },
8
+ {
9
+ cve: "CVE-2026-21636",
10
+ summary: "Unix domain socket connections bypass the network permission",
11
+ fixed: { 25: "25.3.0" },
12
+ },
13
+ {
14
+ cve: "CVE-2026-48935",
15
+ summary: "FileHandle.utimes() can modify paths granted read-only",
16
+ fixed: { 22: "22.23.0", 24: "24.17.0", 26: "26.3.1" },
17
+ },
18
+ {
19
+ cve: "CVE-2026-56847",
20
+ summary: "trace_events can write files outside --allow-fs-write paths",
21
+ fixed: { 22: "22.23.2", 24: "24.18.1", 26: "26.5.1" },
22
+ },
23
+ ];
24
+ /** Release lines that no longer receive security fixes. */
25
+ export const END_OF_LIFE_MAJORS = new Set([20, 21, 23, 25]);
26
+ /** Warnings for a Node version used to run tools; empty when fully patched. */
27
+ export function nodeAdvisoriesFor(version) {
28
+ const [major] = parseVersion(version);
29
+ const warnings = [];
30
+ if (END_OF_LIFE_MAJORS.has(major)) {
31
+ warnings.push(`Node ${version} is end-of-life and no longer receives permission-model fixes; upgrade to an LTS line (22, 24 or 26).`);
32
+ }
33
+ for (const advisory of NODE_ADVISORIES) {
34
+ const fixed = advisory.fixed[major];
35
+ if (fixed && compareVersions(version, fixed) < 0) {
36
+ warnings.push(`${advisory.cve}: ${advisory.summary} (fixed in ${fixed}).`);
37
+ }
38
+ }
39
+ return warnings;
40
+ }
41
+ //# sourceMappingURL=node-advisories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-advisories.js","sourceRoot":"","sources":["../src/node-advisories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAclE,MAAM,CAAC,MAAM,eAAe,GAA4B;IACtD;QACE,GAAG,EAAE,gBAAgB;QACrB,OAAO,EAAE,+DAA+D;QACxE,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE;KACrE;IACD;QACE,GAAG,EAAE,gBAAgB;QACrB,OAAO,EAAE,8DAA8D;QACvE,KAAK,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE;KACxB;IACD;QACE,GAAG,EAAE,gBAAgB;QACrB,OAAO,EAAE,wDAAwD;QACjE,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE;KACtD;IACD;QACE,GAAG,EAAE,gBAAgB;QACrB,OAAO,EAAE,6DAA6D;QACtE,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE;KACtD;CACF,CAAC;AAEF,2DAA2D;AAC3D,MAAM,CAAC,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAEjF,+EAA+E;AAC/E,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,MAAM,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,QAAQ,CAAC,IAAI,CACX,QAAQ,OAAO,uGAAuG,CACvH,CAAC;IACJ,CAAC;IACD,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,KAAK,IAAI,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACjD,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,GAAG,KAAK,QAAQ,CAAC,OAAO,cAAc,KAAK,IAAI,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,20 @@
1
+ export interface NodeRuntime {
2
+ path: string;
3
+ version: string;
4
+ major: number;
5
+ /** `native`: `--permission` denies sockets (Node ≥25). `guard`: JS-level best-effort guard. */
6
+ netMode: "native" | "guard";
7
+ /**
8
+ * Test-only: on Node ≥25, open the network natively and rely on the guard alone,
9
+ * so the Node 22/24 code path can be exercised without installing old Node.
10
+ */
11
+ simulateGuard?: boolean;
12
+ }
13
+ export declare function parseVersion(version: string): [number, number, number];
14
+ export declare function compareVersions(a: string, b: string): number;
15
+ /**
16
+ * The Node binary used for tool processes: explicit `nodePath`, then
17
+ * `TOOLPAL_NODE`, then the current process. Throws below the supported minimum.
18
+ */
19
+ export declare function resolveNodeRuntime(nodePath?: string): Promise<NodeRuntime>;
20
+ //# sourceMappingURL=node-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-version.d.ts","sourceRoot":"","sources":["../src/node-version.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,+FAA+F;IAC/F,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAItE;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ5D;AAID;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAS1E"}
@@ -0,0 +1,61 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { MIN_NODE_VERSION, NATIVE_NET_NODE_MAJOR } from "@toolpal/manifest";
4
+ import { SandboxError } from "./errors.js";
5
+ const execFileAsync = promisify(execFile);
6
+ export function parseVersion(version) {
7
+ const m = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version.trim());
8
+ if (!m)
9
+ throw new Error(`Unrecognized Node.js version "${version}"`);
10
+ return [Number(m[1]), Number(m[2]), Number(m[3])];
11
+ }
12
+ export function compareVersions(a, b) {
13
+ const pa = parseVersion(a);
14
+ const pb = parseVersion(b);
15
+ for (let i = 0; i < 3; i++) {
16
+ const d = pa[i] - pb[i];
17
+ if (d !== 0)
18
+ return d;
19
+ }
20
+ return 0;
21
+ }
22
+ const cache = new Map();
23
+ /**
24
+ * The Node binary used for tool processes: explicit `nodePath`, then
25
+ * `TOOLPAL_NODE`, then the current process. Throws below the supported minimum.
26
+ */
27
+ export function resolveNodeRuntime(nodePath) {
28
+ const path = nodePath ?? process.env.TOOLPAL_NODE ?? process.execPath;
29
+ let pending = cache.get(path);
30
+ if (!pending) {
31
+ pending = probe(path);
32
+ cache.set(path, pending);
33
+ pending.catch(() => cache.delete(path));
34
+ }
35
+ return pending;
36
+ }
37
+ async function probe(path) {
38
+ let version;
39
+ if (path === process.execPath) {
40
+ version = process.versions.node;
41
+ }
42
+ else {
43
+ try {
44
+ const { stdout } = await execFileAsync(path, ["--version"], {
45
+ timeout: 10_000,
46
+ windowsHide: true,
47
+ });
48
+ version = stdout.trim().replace(/^v/, "");
49
+ }
50
+ catch (err) {
51
+ throw new SandboxError("UNSUPPORTED_NODE", `Cannot run Node.js at ${path}: ${err.message}`);
52
+ }
53
+ }
54
+ if (compareVersions(version, MIN_NODE_VERSION) < 0) {
55
+ throw new SandboxError("UNSUPPORTED_NODE", `Toolpal needs Node.js >= ${MIN_NODE_VERSION} to run tools (found ${version} at ${path}). ` +
56
+ "Upgrade Node, or point TOOLPAL_NODE at a newer node binary.", { version, path });
57
+ }
58
+ const [major] = parseVersion(version);
59
+ return { path, version, major, netMode: major >= NATIVE_NET_NODE_MAJOR ? "native" : "guard" };
60
+ }
61
+ //# sourceMappingURL=node-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-version.js","sourceRoot":"","sources":["../src/node-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,qBAA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EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,qBAAqB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAChG,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Readable } from "node:stream";
2
+ export interface Frame {
3
+ type: string;
4
+ [key: string]: unknown;
5
+ }
6
+ export interface FrameReaderOptions {
7
+ maxFrameBytes: number;
8
+ onFrame: (frame: Frame) => void;
9
+ onViolation: (reason: string) => void;
10
+ }
11
+ /**
12
+ * Newline-delimited JSON frames from an untrusted child. The byte cap applies
13
+ * before parsing, and parsing strips `__proto__`/`constructor.prototype` keys.
14
+ */
15
+ export declare function readFrames(stream: Readable, opts: FrameReaderOptions): void;
16
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAkD3E"}