@jini-ai/sandbox 0.4.0 → 0.4.2

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,18 @@ 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.
108
+ * Worker stdin is disabled and output is drained without forwarding to parent stdio;
109
+ * results and controlled failures travel over the message/error ports instead.
96
110
  * @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.
111
+ * @param options Optional native creation port and TypeScript registration module; its eval entry suppresses V8 coverage.
98
112
  * @returns WorkerFactory for caller-owned JS/TS entry paths, with no package-relative lookup.
99
113
  * @complexity O(e) environment copying for e variables, excluding native worker startup.
100
114
  */
@@ -101,8 +101,10 @@ function renderInWorkerSandbox(required, options = {}) {
101
101
  }
102
102
  /**
103
103
  * Native Node worker factory. TypeScript bootstrap configuration is explicit and host-owned.
104
+ * Worker stdin is disabled and output is drained without forwarding to parent stdio;
105
+ * results and controlled failures travel over the message/error ports instead.
104
106
  * @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.
107
+ * @param options Optional native creation port and TypeScript registration module; its eval entry suppresses V8 coverage.
106
108
  * @returns WorkerFactory for caller-owned JS/TS entry paths, with no package-relative lookup.
107
109
  * @complexity O(e) environment copying for e variables, excluding native worker startup.
108
110
  */
@@ -110,6 +112,10 @@ function createNodeWorkerFactory({ env }, options = {}) {
110
112
  return {
111
113
  spawn({ workerEntry, payload, resourceLimits }) {
112
114
  const workerEnv = { ...env };
115
+ const workerOptions = {
116
+ workerData: payload, resourceLimits, env: workerEnv, execArgv: [],
117
+ stdin: false, stdout: true, stderr: true,
118
+ };
113
119
  let worker;
114
120
  // A CommonJS-typed TS entry bypasses --import loader hooks for its first file and
115
121
  // can fail with "Cannot use import statement outside a module" despite the flag.
@@ -126,11 +132,16 @@ function createNodeWorkerFactory({ env }, options = {}) {
126
132
  // directory is created merely to leave cleanup behind.
127
133
  delete workerEnv.NODE_V8_COVERAGE;
128
134
  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: [] });
135
+ workerOptions.eval = true;
136
+ worker = options.createWorker ? options.createWorker({ entry: bootstrap, options: workerOptions }, {}) : new node_worker_threads_1.Worker(bootstrap, workerOptions);
130
137
  }
131
138
  else {
132
- worker = new node_worker_threads_1.Worker(workerEntry, { workerData: payload, resourceLimits, env: workerEnv, execArgv: [] });
139
+ worker = options.createWorker ? options.createWorker({ entry: workerEntry, options: workerOptions }, {}) : new node_worker_threads_1.Worker(workerEntry, workerOptions);
133
140
  }
141
+ // Explicit output streams avoid Node's automatic forwarding to detached parent
142
+ // streams. Drain them so worker logging cannot block a render or grow a buffer.
143
+ worker.stdout.resume();
144
+ worker.stderr.resume();
134
145
  return {
135
146
  once(input) {
136
147
  if (input.event === "message")
@@ -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,18 @@ 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.
108
+ * Worker stdin is disabled and output is drained without forwarding to parent stdio;
109
+ * results and controlled failures travel over the message/error ports instead.
96
110
  * @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.
111
+ * @param options Optional native creation port and TypeScript registration module; its eval entry suppresses V8 coverage.
98
112
  * @returns WorkerFactory for caller-owned JS/TS entry paths, with no package-relative lookup.
99
113
  * @complexity O(e) environment copying for e variables, excluding native worker startup.
100
114
  */
@@ -94,8 +94,10 @@ export function renderInWorkerSandbox(required, options = {}) {
94
94
  }
95
95
  /**
96
96
  * Native Node worker factory. TypeScript bootstrap configuration is explicit and host-owned.
97
+ * Worker stdin is disabled and output is drained without forwarding to parent stdio;
98
+ * results and controlled failures travel over the message/error ports instead.
97
99
  * @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.
100
+ * @param options Optional native creation port and TypeScript registration module; its eval entry suppresses V8 coverage.
99
101
  * @returns WorkerFactory for caller-owned JS/TS entry paths, with no package-relative lookup.
100
102
  * @complexity O(e) environment copying for e variables, excluding native worker startup.
101
103
  */
@@ -103,6 +105,10 @@ export function createNodeWorkerFactory({ env }, options = {}) {
103
105
  return {
104
106
  spawn({ workerEntry, payload, resourceLimits }) {
105
107
  const workerEnv = { ...env };
108
+ const workerOptions = {
109
+ workerData: payload, resourceLimits, env: workerEnv, execArgv: [],
110
+ stdin: false, stdout: true, stderr: true,
111
+ };
106
112
  let worker;
107
113
  // A CommonJS-typed TS entry bypasses --import loader hooks for its first file and
108
114
  // can fail with "Cannot use import statement outside a module" despite the flag.
@@ -119,11 +125,16 @@ export function createNodeWorkerFactory({ env }, options = {}) {
119
125
  // directory is created merely to leave cleanup behind.
120
126
  delete workerEnv.NODE_V8_COVERAGE;
121
127
  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: [] });
128
+ workerOptions.eval = true;
129
+ worker = options.createWorker ? options.createWorker({ entry: bootstrap, options: workerOptions }, {}) : new Worker(bootstrap, workerOptions);
123
130
  }
124
131
  else {
125
- worker = new Worker(workerEntry, { workerData: payload, resourceLimits, env: workerEnv, execArgv: [] });
132
+ worker = options.createWorker ? options.createWorker({ entry: workerEntry, options: workerOptions }, {}) : new Worker(workerEntry, workerOptions);
126
133
  }
134
+ // Explicit output streams avoid Node's automatic forwarding to detached parent
135
+ // streams. Drain them so worker logging cannot block a render or grow a buffer.
136
+ worker.stdout.resume();
137
+ worker.stderr.resume();
127
138
  return {
128
139
  once(input) {
129
140
  if (input.event === "message")
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.2",
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": {