@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @jini-ai/sandbox
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Tovu clean-up release (2026-10-08): code Tovu moved into Jini, plus the Jini clean-up (see the commit log since 0.4.0).
8
+
3
9
  ## 0.4.0 — 2026-10-02
4
10
 
5
11
  ### BREAKING
@@ -1,4 +1,11 @@
1
- import type { ResourceLimits } from "node:worker_threads";
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
  */
@@ -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
- worker = new node_worker_threads_1.Worker(bootstrap, { eval: true, workerData: payload, resourceLimits, env: workerEnv, execArgv: [] });
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
- worker = new node_worker_threads_1.Worker(workerEntry, { workerData: payload, resourceLimits, env: workerEnv, execArgv: [] });
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) {
@@ -1,4 +1,11 @@
1
- import type { ResourceLimits } from "node:worker_threads";
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
  */
@@ -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
- worker = new Worker(bootstrap, { eval: true, workerData: payload, resourceLimits, env: workerEnv, execArgv: [] });
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
- worker = new Worker(workerEntry, { workerData: payload, resourceLimits, env: workerEnv, execArgv: [] });
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.0",
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": {