@jini-ai/sandbox 0.4.0 → 0.4.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/CHANGELOG.md +6 -0
- package/dist/cjs/node-worker.d.ts +14 -2
- package/dist/cjs/node-worker.js +5 -3
- package/dist/node-worker.d.ts +14 -2
- package/dist/node-worker.js +5 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* CPU-bound synchronous work cannot be pre-empted by a Promise.race timer on that same
|
|
3
|
+
* thread. A fresh worker lets the parent terminate runaway work and apply V8 heap limits
|
|
4
|
+
* without wedging or exhausting the main server. Node workers avoid a native sandbox
|
|
5
|
+
* build dependency and the known escape vulnerabilities of vm2.
|
|
6
|
+
*/
|
|
7
|
+
import { Worker } from "node:worker_threads";
|
|
8
|
+
import type { ResourceLimits, WorkerOptions } from "node:worker_threads";
|
|
2
9
|
export type WorkerSubscription = {
|
|
3
10
|
event: "message";
|
|
4
11
|
listener: (input: {
|
|
@@ -90,11 +97,16 @@ export interface NodeWorkerFactoryOptions {
|
|
|
90
97
|
typescriptBootstrap?: {
|
|
91
98
|
registerModulePath: string;
|
|
92
99
|
};
|
|
100
|
+
/** Native creation effect port; this factory still owns bootstrap, environment and budgets. */
|
|
101
|
+
createWorker?: (input: {
|
|
102
|
+
entry: string | URL;
|
|
103
|
+
options: WorkerOptions;
|
|
104
|
+
}, optional?: Record<string, never>) => Worker;
|
|
93
105
|
}
|
|
94
106
|
/**
|
|
95
107
|
* Native Node worker factory. TypeScript bootstrap configuration is explicit and host-owned.
|
|
96
108
|
* @param required Environment copied to each worker; nothing reads the parent environment.
|
|
97
|
-
* @param options Optional TypeScript registration module; its eval entry suppresses V8 coverage.
|
|
109
|
+
* @param options Optional native creation port and TypeScript registration module; its eval entry suppresses V8 coverage.
|
|
98
110
|
* @returns WorkerFactory for caller-owned JS/TS entry paths, with no package-relative lookup.
|
|
99
111
|
* @complexity O(e) environment copying for e variables, excluding native worker startup.
|
|
100
112
|
*/
|
package/dist/cjs/node-worker.js
CHANGED
|
@@ -102,7 +102,7 @@ function renderInWorkerSandbox(required, options = {}) {
|
|
|
102
102
|
/**
|
|
103
103
|
* Native Node worker factory. TypeScript bootstrap configuration is explicit and host-owned.
|
|
104
104
|
* @param required Environment copied to each worker; nothing reads the parent environment.
|
|
105
|
-
* @param options Optional TypeScript registration module; its eval entry suppresses V8 coverage.
|
|
105
|
+
* @param options Optional native creation port and TypeScript registration module; its eval entry suppresses V8 coverage.
|
|
106
106
|
* @returns WorkerFactory for caller-owned JS/TS entry paths, with no package-relative lookup.
|
|
107
107
|
* @complexity O(e) environment copying for e variables, excluding native worker startup.
|
|
108
108
|
*/
|
|
@@ -126,10 +126,12 @@ function createNodeWorkerFactory({ env }, options = {}) {
|
|
|
126
126
|
// directory is created merely to leave cleanup behind.
|
|
127
127
|
delete workerEnv.NODE_V8_COVERAGE;
|
|
128
128
|
const bootstrap = `require(${JSON.stringify(options.typescriptBootstrap.registerModulePath)}).register();\nrequire(${JSON.stringify(workerEntry)});\n`;
|
|
129
|
-
|
|
129
|
+
const workerOptions = { eval: true, workerData: payload, resourceLimits, env: workerEnv, execArgv: [] };
|
|
130
|
+
worker = options.createWorker ? options.createWorker({ entry: bootstrap, options: workerOptions }, {}) : new node_worker_threads_1.Worker(bootstrap, workerOptions);
|
|
130
131
|
}
|
|
131
132
|
else {
|
|
132
|
-
|
|
133
|
+
const workerOptions = { workerData: payload, resourceLimits, env: workerEnv, execArgv: [] };
|
|
134
|
+
worker = options.createWorker ? options.createWorker({ entry: workerEntry, options: workerOptions }, {}) : new node_worker_threads_1.Worker(workerEntry, workerOptions);
|
|
133
135
|
}
|
|
134
136
|
return {
|
|
135
137
|
once(input) {
|
package/dist/node-worker.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* CPU-bound synchronous work cannot be pre-empted by a Promise.race timer on that same
|
|
3
|
+
* thread. A fresh worker lets the parent terminate runaway work and apply V8 heap limits
|
|
4
|
+
* without wedging or exhausting the main server. Node workers avoid a native sandbox
|
|
5
|
+
* build dependency and the known escape vulnerabilities of vm2.
|
|
6
|
+
*/
|
|
7
|
+
import { Worker } from "node:worker_threads";
|
|
8
|
+
import type { ResourceLimits, WorkerOptions } from "node:worker_threads";
|
|
2
9
|
export type WorkerSubscription = {
|
|
3
10
|
event: "message";
|
|
4
11
|
listener: (input: {
|
|
@@ -90,11 +97,16 @@ export interface NodeWorkerFactoryOptions {
|
|
|
90
97
|
typescriptBootstrap?: {
|
|
91
98
|
registerModulePath: string;
|
|
92
99
|
};
|
|
100
|
+
/** Native creation effect port; this factory still owns bootstrap, environment and budgets. */
|
|
101
|
+
createWorker?: (input: {
|
|
102
|
+
entry: string | URL;
|
|
103
|
+
options: WorkerOptions;
|
|
104
|
+
}, optional?: Record<string, never>) => Worker;
|
|
93
105
|
}
|
|
94
106
|
/**
|
|
95
107
|
* Native Node worker factory. TypeScript bootstrap configuration is explicit and host-owned.
|
|
96
108
|
* @param required Environment copied to each worker; nothing reads the parent environment.
|
|
97
|
-
* @param options Optional TypeScript registration module; its eval entry suppresses V8 coverage.
|
|
109
|
+
* @param options Optional native creation port and TypeScript registration module; its eval entry suppresses V8 coverage.
|
|
98
110
|
* @returns WorkerFactory for caller-owned JS/TS entry paths, with no package-relative lookup.
|
|
99
111
|
* @complexity O(e) environment copying for e variables, excluding native worker startup.
|
|
100
112
|
*/
|
package/dist/node-worker.js
CHANGED
|
@@ -95,7 +95,7 @@ export function renderInWorkerSandbox(required, options = {}) {
|
|
|
95
95
|
/**
|
|
96
96
|
* Native Node worker factory. TypeScript bootstrap configuration is explicit and host-owned.
|
|
97
97
|
* @param required Environment copied to each worker; nothing reads the parent environment.
|
|
98
|
-
* @param options Optional TypeScript registration module; its eval entry suppresses V8 coverage.
|
|
98
|
+
* @param options Optional native creation port and TypeScript registration module; its eval entry suppresses V8 coverage.
|
|
99
99
|
* @returns WorkerFactory for caller-owned JS/TS entry paths, with no package-relative lookup.
|
|
100
100
|
* @complexity O(e) environment copying for e variables, excluding native worker startup.
|
|
101
101
|
*/
|
|
@@ -119,10 +119,12 @@ export function createNodeWorkerFactory({ env }, options = {}) {
|
|
|
119
119
|
// directory is created merely to leave cleanup behind.
|
|
120
120
|
delete workerEnv.NODE_V8_COVERAGE;
|
|
121
121
|
const bootstrap = `require(${JSON.stringify(options.typescriptBootstrap.registerModulePath)}).register();\nrequire(${JSON.stringify(workerEntry)});\n`;
|
|
122
|
-
|
|
122
|
+
const workerOptions = { eval: true, workerData: payload, resourceLimits, env: workerEnv, execArgv: [] };
|
|
123
|
+
worker = options.createWorker ? options.createWorker({ entry: bootstrap, options: workerOptions }, {}) : new Worker(bootstrap, workerOptions);
|
|
123
124
|
}
|
|
124
125
|
else {
|
|
125
|
-
|
|
126
|
+
const workerOptions = { workerData: payload, resourceLimits, env: workerEnv, execArgv: [] };
|
|
127
|
+
worker = options.createWorker ? options.createWorker({ entry: workerEntry, options: workerOptions }, {}) : new Worker(workerEntry, workerOptions);
|
|
126
128
|
}
|
|
127
129
|
return {
|
|
128
130
|
once(input) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/sandbox",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Execution/sandbox sibling to @jini-ai/vibecoding's edit loop: boot an environment, mount files, install deps, run commands, preview, and tear down — behind one interface with a driver-neutral core. Import `./core` with no adapter installed; add `./e2b` for the E2B (Firecracker microVM) backend.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|