@memberjunction/code-execution 4.0.0 → 4.2.0

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.
@@ -1,6 +1,4 @@
1
-
2
- 
3
- > @memberjunction/code-execution@4.0.0 build
4
- > tsc && tsc-alias -f
5
-
6
- ⠙
1
+
2
+ > @memberjunction/code-execution@4.2.0 build
3
+ > tsc && tsc-alias -f
4
+
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @memberjunction/code-execution
2
2
 
3
+ ## 4.2.0
4
+
5
+ ### Patch Changes
6
+
7
+ - @memberjunction/core@4.2.0
8
+ - @memberjunction/global@4.2.0
9
+
10
+ ## 4.1.0
11
+
12
+ ### Patch Changes
13
+
14
+ - 9fab8ca: ESM Compatibility
15
+ - Updated dependencies [77839a9]
16
+ - Updated dependencies [5af036f]
17
+ - @memberjunction/core@4.1.0
18
+ - @memberjunction/global@4.1.0
19
+
3
20
  ## 4.0.0
4
21
 
5
22
  ### Major Changes
package/README.md CHANGED
@@ -1,24 +1,16 @@
1
1
  # @memberjunction/code-execution
2
2
 
3
- Sandboxed JavaScript code execution service for MemberJunction AI agents and workflows.
3
+ Sandboxed JavaScript code execution service for MemberJunction AI agents and workflows. Executes untrusted code in isolated worker processes using V8 isolates (`isolated-vm`) with a defense-in-depth security model.
4
4
 
5
- ## Overview
5
+ > **Parent package**: This package is part of the [MemberJunction Actions Framework](../README.md). For general Actions architecture, design philosophy, and the boundary between Actions and internal code, see the [parent CLAUDE.md](../CLAUDE.md).
6
6
 
7
- This package provides secure, isolated execution of JavaScript code in a sandboxed environment using `isolated-vm` with worker process isolation. It's designed to enable AI agents to generate and run code for data analysis, transformations, and calculations without compromising system security or stability.
7
+ ## Overview
8
8
 
9
- **⚠️ Security**: This package handles untrusted code execution. Please review [security-research.md](./security-research.md) for comprehensive security analysis, threat model, and implementation details.
9
+ This package provides secure, isolated execution of JavaScript code for scenarios where AI agents or workflows need to generate and run code dynamically -- data analysis, transformations, calculations, and more. It uses a multi-layer security architecture to ensure that untrusted code cannot compromise system security or stability.
10
10
 
11
- ## Features
11
+ The service manages a pool of worker processes, each running code inside V8 isolates via the `isolated-vm` library. If a worker crashes due to a catastrophic error (e.g., V8 OOM), only that worker terminates and is automatically restarted -- the main application remains unaffected.
12
12
 
13
- - **Multi-Layer Security**: 5 independent defense layers (process isolation, V8 isolates, module blocking, resource limits, library allowlist)
14
- - **Fault Isolation**: Workers run in separate processes - crashes don't affect main application
15
- - **Automatic Recovery**: Crashed workers automatically restart with circuit breaker protection
16
- - **Timeout Protection**: Configurable execution timeouts (default: 30 seconds)
17
- - **Memory Limits**: Configurable per-execution memory limits (default: 128MB)
18
- - **Safe Library Access**: Curated allowlist of npm packages with inline implementations
19
- - **Console Logging**: Captures console output for debugging
20
- - **Type Safety**: Full TypeScript support with comprehensive interfaces
21
- - **Audit Trail**: Integrated with MemberJunction action logging
13
+ For comprehensive security analysis, threat model, and implementation details, see [security-research.md](./security-research.md).
22
14
 
23
15
  ## Installation
24
16
 
@@ -26,6 +18,113 @@ This package provides secure, isolated execution of JavaScript code in a sandbox
26
18
  npm install @memberjunction/code-execution
27
19
  ```
28
20
 
21
+ This package is server-side only (Node.js). It requires the `isolated-vm` native module, which compiles during installation.
22
+
23
+ ## Architecture
24
+
25
+ ### Execution Flow
26
+
27
+ ```mermaid
28
+ flowchart TB
29
+ subgraph MainProcess["Main Application Process"]
30
+ CES["CodeExecutionService"]
31
+ WP["WorkerPool"]
32
+ Q["Request Queue"]
33
+ CES --> WP
34
+ WP --> Q
35
+ end
36
+
37
+ subgraph W1["Worker Process 1"]
38
+ IV1["isolated-vm Isolate"]
39
+ CTX1["V8 Context"]
40
+ SB1["Sandbox\n(user code)"]
41
+ IV1 --> CTX1 --> SB1
42
+ end
43
+
44
+ subgraph W2["Worker Process 2"]
45
+ IV2["isolated-vm Isolate"]
46
+ CTX2["V8 Context"]
47
+ SB2["Sandbox\n(user code)"]
48
+ IV2 --> CTX2 --> SB2
49
+ end
50
+
51
+ WP -- "IPC (JSON)" --> W1
52
+ WP -- "IPC (JSON)" --> W2
53
+
54
+ style MainProcess fill:#2d6a9f,stroke:#1a4971,color:#fff
55
+ style W1 fill:#2d8659,stroke:#1a5c3a,color:#fff
56
+ style W2 fill:#2d8659,stroke:#1a5c3a,color:#fff
57
+ style CES fill:#7c5295,stroke:#563a6b,color:#fff
58
+ style WP fill:#7c5295,stroke:#563a6b,color:#fff
59
+ style Q fill:#b8762f,stroke:#8a5722,color:#fff
60
+ style IV1 fill:#2d6a9f,stroke:#1a4971,color:#fff
61
+ style IV2 fill:#2d6a9f,stroke:#1a4971,color:#fff
62
+ style CTX1 fill:#b8762f,stroke:#8a5722,color:#fff
63
+ style CTX2 fill:#b8762f,stroke:#8a5722,color:#fff
64
+ style SB1 fill:#7c5295,stroke:#563a6b,color:#fff
65
+ style SB2 fill:#7c5295,stroke:#563a6b,color:#fff
66
+ ```
67
+
68
+ ### Security Layers
69
+
70
+ The package uses a **defense-in-depth** approach with five independent security layers:
71
+
72
+ ```mermaid
73
+ flowchart LR
74
+ Code["Untrusted\nCode"] --> L1
75
+ L1["Layer 1\nProcess\nIsolation"] --> L2["Layer 2\nV8 Isolate\n(isolated-vm)"]
76
+ L2 --> L3["Layer 3\nModule\nBlocking"]
77
+ L3 --> L4["Layer 4\nResource\nLimits"]
78
+ L4 --> L5["Layer 5\nLibrary\nAllowlist"]
79
+ L5 --> Exec["Safe\nExecution"]
80
+
81
+ style Code fill:#b8762f,stroke:#8a5722,color:#fff
82
+ style L1 fill:#2d6a9f,stroke:#1a4971,color:#fff
83
+ style L2 fill:#2d6a9f,stroke:#1a4971,color:#fff
84
+ style L3 fill:#2d6a9f,stroke:#1a4971,color:#fff
85
+ style L4 fill:#2d6a9f,stroke:#1a4971,color:#fff
86
+ style L5 fill:#2d6a9f,stroke:#1a4971,color:#fff
87
+ style Exec fill:#2d8659,stroke:#1a5c3a,color:#fff
88
+ ```
89
+
90
+ | Layer | Mechanism | Protects Against |
91
+ |-------|-----------|-----------------|
92
+ | Process Isolation | Workers run in separate OS processes via `child_process.fork()` | V8 catastrophic failures crashing the main app |
93
+ | V8 Isolates | Each execution runs in an isolated V8 context (`isolated-vm`) | Sandbox escape, cross-execution data leakage |
94
+ | Module Blocking | Dangerous Node.js modules blocked (`fs`, `http`, `child_process`, etc.) | Filesystem access, network requests, process spawning |
95
+ | Resource Limits | Configurable timeout and memory limits per execution | Denial-of-service via infinite loops or memory exhaustion |
96
+ | Library Allowlist | Only pre-vetted libraries available via `require()` | Supply chain attacks, unsafe library usage |
97
+
98
+ ### Internal Module Structure
99
+
100
+ ```mermaid
101
+ flowchart TB
102
+ IDX["index.ts\n(public exports)"]
103
+ CES["CodeExecutionService\n(main entry point)"]
104
+ WP["WorkerPool\n(process management)"]
105
+ WKR["worker.ts\n(child process)"]
106
+ LIB["libraries/\n(allowlisted modules)"]
107
+ TYP["types/\n(interfaces)"]
108
+
109
+ IDX --> CES
110
+ IDX --> WP
111
+ IDX --> LIB
112
+ IDX --> TYP
113
+
114
+ CES --> WP
115
+ CES --> TYP
116
+ WP --> TYP
117
+ WKR --> TYP
118
+ WKR --> LIB
119
+
120
+ style IDX fill:#7c5295,stroke:#563a6b,color:#fff
121
+ style CES fill:#2d6a9f,stroke:#1a4971,color:#fff
122
+ style WP fill:#2d6a9f,stroke:#1a4971,color:#fff
123
+ style WKR fill:#2d8659,stroke:#1a5c3a,color:#fff
124
+ style LIB fill:#b8762f,stroke:#8a5722,color:#fff
125
+ style TYP fill:#b8762f,stroke:#8a5722,color:#fff
126
+ ```
127
+
29
128
  ## Usage
30
129
 
31
130
  ### Direct TypeScript Usage
@@ -38,10 +137,10 @@ const service = new CodeExecutionService({
38
137
  poolSize: 2, // Number of worker processes (default: 2)
39
138
  maxQueueSize: 100, // Max queued requests (default: 100)
40
139
  maxCrashesPerWorker: 3, // Crashes before marking unhealthy (default: 3)
41
- crashTimeWindow: 60000 // Time window for crash counting (default: 60s)
140
+ crashTimeWindow: 60000 // Time window for crash counting in ms (default: 60000)
42
141
  });
43
142
 
44
- // Initialize the worker pool (can also be done automatically on first execute)
143
+ // Initialize the worker pool (also auto-initializes on first execute)
45
144
  await service.initialize();
46
145
 
47
146
  // Execute code
@@ -53,8 +152,8 @@ const result = await service.execute({
53
152
  `,
54
153
  language: 'javascript',
55
154
  inputData: { values: [10, 20, 30, 40, 50] },
56
- timeoutSeconds: 30, // Optional: execution timeout (default: 30)
57
- memoryLimitMB: 128 // Optional: memory limit (default: 128)
155
+ timeoutSeconds: 30, // Optional (default: 30)
156
+ memoryLimitMB: 128 // Optional (default: 128)
58
157
  });
59
158
 
60
159
  if (result.success) {
@@ -75,9 +174,9 @@ console.log('Queue length:', stats.queueLength);
75
174
  await service.shutdown();
76
175
  ```
77
176
 
78
- ### With Actions (for AI Agents)
177
+ ### With MemberJunction Actions (for AI Agents)
79
178
 
80
- Agents use the "Execute Code" action:
179
+ AI agents interact with the sandbox through the "Execute Code" action:
81
180
 
82
181
  ```json
83
182
  {
@@ -93,146 +192,169 @@ Agents use the "Execute Code" action:
93
192
  }
94
193
  ```
95
194
 
96
- ## Supported Libraries
195
+ ## API Reference
97
196
 
98
- The sandbox includes these pre-approved npm packages:
197
+ ### CodeExecutionService
99
198
 
100
- - **lodash** - Data manipulation and utilities
101
- - **date-fns** - Modern date library
102
- - **mathjs** - Advanced mathematics
103
- - **papaparse** - CSV parsing
104
- - **uuid** - UUID generation
105
- - **validator** - String validation and sanitization
199
+ The main entry point for executing sandboxed code.
106
200
 
107
- ### Using Libraries in Code
201
+ #### Constructor
108
202
 
109
203
  ```typescript
110
- const result = await service.execute({
111
- code: `
112
- const _ = require('lodash');
113
- const { format, addDays } = require('date-fns');
114
- const math = require('mathjs');
204
+ constructor(options?: WorkerPoolOptions)
205
+ ```
115
206
 
116
- // Group data by category
117
- const grouped = _.groupBy(input.data, 'category');
118
-
119
- // Calculate statistics
120
- const stats = {};
121
- for (const [category, items] of Object.entries(grouped)) {
122
- const values = items.map(i => i.value);
123
- stats[category] = {
124
- mean: math.mean(values),
125
- median: math.median(values),
126
- total: math.sum(values)
127
- };
128
- }
207
+ | Option | Type | Default | Description |
208
+ |--------|------|---------|-------------|
209
+ | `poolSize` | `number` | `2` | Number of worker processes to maintain |
210
+ | `maxQueueSize` | `number` | `100` | Maximum requests to queue before rejecting |
211
+ | `maxCrashesPerWorker` | `number` | `3` | Crash count threshold before disabling a worker |
212
+ | `crashTimeWindow` | `number` | `60000` | Time window (ms) for crash counting |
129
213
 
130
- output = stats;
131
- `,
132
- language: 'javascript',
133
- inputData: {
134
- data: [
135
- { category: 'A', value: 10 },
136
- { category: 'B', value: 20 },
137
- { category: 'A', value: 15 }
138
- ]
139
- }
140
- });
214
+ #### Methods
215
+
216
+ | Method | Returns | Description |
217
+ |--------|---------|-------------|
218
+ | `initialize()` | `Promise<void>` | Start worker processes. Called automatically on first `execute()` if not called explicitly. |
219
+ | `execute(params)` | `Promise<CodeExecutionResult>` | Execute code in a sandboxed worker. See `CodeExecutionParams` below. |
220
+ | `getStats()` | `PoolStats` | Get current pool statistics (worker count, busy count, queue length). |
221
+ | `shutdown()` | `Promise<void>` | Gracefully terminate all workers and reject pending requests. |
222
+
223
+ ### CodeExecutionParams
224
+
225
+ ```typescript
226
+ interface CodeExecutionParams {
227
+ code: string; // JavaScript code to execute
228
+ language: 'javascript'; // Currently only 'javascript' supported
229
+ inputData?: unknown; // Data available as the 'input' variable in sandbox
230
+ timeoutSeconds?: number; // Max execution time in seconds (default: 30)
231
+ memoryLimitMB?: number; // Memory limit per execution in MB (default: 128)
232
+ }
233
+ ```
234
+
235
+ ### CodeExecutionResult
236
+
237
+ ```typescript
238
+ interface CodeExecutionResult {
239
+ success: boolean; // Whether execution completed without error
240
+ output?: unknown; // Value of the 'output' variable set by executed code
241
+ logs?: string[]; // Captured console output (log, error, warn, info)
242
+ error?: string; // Error message if execution failed
243
+ errorType?: 'TIMEOUT' | 'MEMORY_LIMIT' | 'SYNTAX_ERROR' | 'RUNTIME_ERROR' | 'SECURITY_ERROR';
244
+ executionTimeMs?: number; // Wall-clock execution duration in milliseconds
245
+ }
141
246
  ```
142
247
 
143
- ## Security Model
248
+ ### WorkerPool
144
249
 
145
- **For detailed security analysis, see [security-research.md](./security-research.md)**
250
+ Manages the pool of worker processes. Typically used through `CodeExecutionService`, but can be instantiated directly for advanced use cases.
146
251
 
147
- This package uses a **defense-in-depth** approach with five independent security layers:
252
+ | Method | Returns | Description |
253
+ |--------|---------|-------------|
254
+ | `initialize()` | `Promise<void>` | Fork worker processes and wait for them to signal ready. |
255
+ | `execute(params)` | `Promise<CodeExecutionResult>` | Queue and execute a request in the next available worker. |
256
+ | `getStats()` | `PoolStats` | Return `totalWorkers`, `activeWorkers`, `busyWorkers`, `queueLength`. |
257
+ | `shutdown()` | `Promise<void>` | Gracefully kill all workers with SIGTERM, force-kill after 5 seconds. |
148
258
 
149
- 1. **Process Isolation** - Workers run in separate OS processes
150
- 2. **V8 Isolates** - Each execution runs in isolated V8 context (via `isolated-vm`)
151
- 3. **Module Blocking** - Dangerous Node.js modules are blocked
152
- 4. **Resource Limits** - Enforced timeout and memory limits
153
- 5. **Library Allowlist** - Only pre-vetted libraries available
259
+ ### Library Functions
260
+
261
+ | Function | Returns | Description |
262
+ |----------|---------|-------------|
263
+ | `isModuleAllowed(name)` | `boolean` | Check if a module name is in the allowlist. |
264
+ | `getAllowedModuleNames()` | `string[]` | Return all allowed module names. |
265
+ | `getLibrarySource(name)` | `string \| null` | Return the JavaScript source for a library (inline or bundled). |
266
+
267
+ ## Sandbox Environment
154
268
 
155
269
  ### What Code CAN Do
156
270
 
157
- - Access input data via `input` variable
158
- - Set output data via `output` variable
159
- - Use console methods (log, error, warn, info)
160
- - Require allowed npm packages (lodash, date-fns, uuid, validator)
271
+ - Access input data via the `input` variable
272
+ - Set output data via the `output` variable
273
+ - Use console methods (`console.log`, `console.error`, `console.warn`, `console.info`)
274
+ - Require allowed npm packages (see below)
161
275
  - Perform calculations and data transformations
162
- - Use safe built-in objects (JSON, Math, Date, Array, Object, String, Number, Boolean)
276
+ - Use safe built-in objects: `JSON`, `Math`, `Date`, `Array`, `Object`, `String`, `Number`, `Boolean`, `RegExp`, `Error`
163
277
 
164
278
  ### What Code CANNOT Do
165
279
 
166
- - Access filesystem (`fs`, `path` modules blocked)
167
- - Make network requests (`http`, `https`, `net`, `axios` modules blocked, `fetch()` API disabled)
280
+ - Access the filesystem (`fs`, `path` modules blocked)
281
+ - Make network requests (`http`, `https`, `net`, `axios` blocked; `fetch()` API disabled)
168
282
  - Spawn processes (`child_process`, `cluster` blocked)
169
283
  - Access system information (`os`, `process` blocked)
170
284
  - Access environment variables
171
- - Use `eval()` or `Function` constructor (for user code)
285
+ - Use `eval()` or `Function` constructor (within user code scope)
172
286
  - Run indefinitely (timeout enforced)
173
- - Exceed memory limits (128MB default)
287
+ - Exceed memory limits (per-isolate enforcement)
174
288
 
175
- ## API Reference
176
-
177
- ### CodeExecutionService
289
+ ### Allowed Libraries
178
290
 
179
- #### `execute(params: CodeExecutionParams): Promise<CodeExecutionResult>`
291
+ The sandbox provides a curated set of pre-vetted libraries accessible via `require()`:
180
292
 
181
- Executes code in a sandboxed environment.
293
+ | Library | Type | Description |
294
+ |---------|------|-------------|
295
+ | `lodash` | Inline subset | Array/collection/object utilities (`chunk`, `groupBy`, `sortBy`, `pick`, `omit`, `get`, `set`, `sum`, `sumBy`, `mean`, `meanBy`, `cloneDeep`, and more) |
296
+ | `date-fns` | Inline subset | Date manipulation (`format`, `addDays`, `subDays`, `addMonths`, `differenceInDays`, `isAfter`, `isBefore`, `startOfDay`, `endOfDay`, `parseISO`) |
297
+ | `mathjs` | Bundled full | Comprehensive mathematics library |
298
+ | `papaparse` | Bundled full | CSV parsing and generation |
299
+ | `jstat` | Bundled full | Statistical distributions, hypothesis testing, regression |
300
+ | `uuid` | Inline | UUID v4 generation |
301
+ | `validator` | Inline subset | String validation (`isEmail`, `isURL`, `isNumeric`, `isAlpha`, `isAlphanumeric`, `isEmpty`, `isLength`, `isIn`, `matches`) |
182
302
 
183
- **Parameters:**
184
-
185
- ```typescript
186
- interface CodeExecutionParams {
187
- code: string; // JavaScript code to execute
188
- language: 'javascript'; // Currently only 'javascript' supported
189
- inputData?: any; // Data available as 'input' variable
190
- timeoutSeconds?: number; // Execution timeout (default: 30)
191
- memoryLimitMB?: number; // Memory limit (default: 128)
192
- }
193
- ```
194
-
195
- **Returns:**
196
-
197
- ```typescript
198
- interface CodeExecutionResult {
199
- success: boolean; // Whether execution succeeded
200
- output?: any; // Value of 'output' variable
201
- logs?: string[]; // Console output
202
- error?: string; // Error message if failed
203
- errorType?: 'TIMEOUT' | 'MEMORY_LIMIT' | 'SYNTAX_ERROR' | 'RUNTIME_ERROR' | 'SECURITY_ERROR';
204
- executionTimeMs?: number; // Execution duration
205
- }
206
- ```
303
+ Libraries marked "Inline subset" are lightweight re-implementations of the most commonly used functions. Libraries marked "Bundled full" are the complete libraries loaded from pre-built JavaScript bundles.
207
304
 
208
305
  ## Error Handling
209
306
 
210
- The service handles various error conditions gracefully:
307
+ The service classifies errors into five categories:
211
308
 
212
309
  ```typescript
213
310
  const result = await service.execute({
214
- code: 'invalid syntax here',
311
+ code: 'while(true) {}', // infinite loop
215
312
  language: 'javascript'
216
313
  });
217
314
 
218
315
  if (!result.success) {
219
316
  switch (result.errorType) {
220
- case 'SYNTAX_ERROR':
221
- console.error('Code has syntax errors:', result.error);
222
- break;
223
317
  case 'TIMEOUT':
224
- console.error('Code execution timed out');
318
+ // Code exceeded the configured timeout
319
+ break;
320
+ case 'MEMORY_LIMIT':
321
+ // Code exceeded the configured memory limit
322
+ break;
323
+ case 'SYNTAX_ERROR':
324
+ // Code has JavaScript syntax errors
225
325
  break;
226
326
  case 'RUNTIME_ERROR':
227
- console.error('Runtime error:', result.error);
327
+ // Code threw an unhandled exception
228
328
  break;
229
329
  case 'SECURITY_ERROR':
230
- console.error('Security violation:', result.error);
330
+ // Code attempted a blocked operation (e.g., requiring 'fs')
231
331
  break;
232
332
  }
233
333
  }
234
334
  ```
235
335
 
336
+ ## Worker Pool Lifecycle
337
+
338
+ The worker pool implements automatic recovery with circuit breaker protection:
339
+
340
+ ```mermaid
341
+ stateDiagram-v2
342
+ [*] --> Idle: Worker created
343
+ Idle --> Busy: Request assigned
344
+ Busy --> Idle: Execution complete
345
+ Busy --> Crashed: Process exit
346
+ Crashed --> Restarting: crashCount < max
347
+ Crashed --> Disabled: crashCount >= max
348
+ Restarting --> Idle: Worker ready
349
+ Disabled --> [*]: Removed from pool
350
+ ```
351
+
352
+ - **Idle**: Worker is ready to accept work.
353
+ - **Busy**: Worker is executing code. New requests are queued.
354
+ - **Crashed**: Worker process exited unexpectedly. Current request is rejected with an error.
355
+ - **Restarting**: Worker is being restarted (automatic). Crash count is tracked within the configured time window.
356
+ - **Disabled**: Too many crashes in the time window. Worker is removed from the pool to prevent crash loops.
357
+
236
358
  ## Examples
237
359
 
238
360
  ### Data Analysis
@@ -242,7 +364,6 @@ const result = await service.execute({
242
364
  code: `
243
365
  const _ = require('lodash');
244
366
 
245
- // Calculate key metrics
246
367
  const metrics = {
247
368
  totalSales: _.sumBy(input.sales, 'amount'),
248
369
  avgSale: _.meanBy(input.sales, 'amount'),
@@ -252,7 +373,7 @@ const result = await service.execute({
252
373
  product,
253
374
  revenue: _.sumBy(items, 'amount')
254
375
  }))
255
- .orderBy('revenue', 'desc')
376
+ .sortBy(x => -x.revenue)
256
377
  .take(5)
257
378
  .value()
258
379
  };
@@ -264,7 +385,7 @@ const result = await service.execute({
264
385
  sales: [
265
386
  { product: 'Widget', amount: 100 },
266
387
  { product: 'Gadget', amount: 200 },
267
- // ... more sales
388
+ { product: 'Widget', amount: 150 }
268
389
  ]
269
390
  }
270
391
  });
@@ -309,7 +430,6 @@ const result = await service.execute({
309
430
  dynamicTyping: true
310
431
  });
311
432
 
312
- // Filter and transform
313
433
  const processed = parsed.data
314
434
  .filter(row => row.status === 'active')
315
435
  .map(row => ({
@@ -322,74 +442,75 @@ const result = await service.execute({
322
442
  `,
323
443
  language: 'javascript',
324
444
  inputData: {
325
- csvData: 'id,name,value,status\n1,Item A,100,active\n2,Item B,200,inactive'
445
+ csvData: 'id,name,value,status\\n1,Item A,100,active\\n2,Item B,200,inactive'
326
446
  }
327
447
  });
328
448
  ```
329
449
 
330
- ## Best Practices
331
-
332
- 1. **Initialize Once**: Create one `CodeExecutionService` instance and reuse it (worker pool is shared)
333
- 2. **Shutdown Gracefully**: Call `service.shutdown()` during application shutdown to clean up workers
334
- 3. **Set Appropriate Timeouts**: Adjust `timeoutSeconds` based on expected workload
335
- 4. **Validate Input Data**: Ensure input data is in expected format before execution
336
- 5. **Handle Errors Gracefully**: Always check `result.success` before using `result.output`
337
- 6. **Monitor Pool Health**: Use `service.getStats()` to monitor worker health and queue depth
338
- 7. **Use Console Logging**: Add `console.log()` statements for debugging
339
- 8. **Leverage Libraries**: Use lodash, date-fns, etc. instead of reinventing the wheel
340
- 9. **Keep Code Focused**: Break complex logic into smaller execution chunks
341
- 10. **Review Security Docs**: Read [security-research.md](./security-research.md) for threat model and security considerations
342
-
343
- ## Architecture
450
+ ### Statistical Analysis
344
451
 
345
- ### Worker Process Pool
346
-
347
- The service maintains a pool of worker processes for fault isolation:
452
+ ```typescript
453
+ const result = await service.execute({
454
+ code: `
455
+ const math = require('mathjs');
348
456
 
349
- ```
350
- ┌─────────────────────────────────────┐
351
- │ Main Application Process │
352
- │ │
353
- │ ┌────────────────────────────┐ │
354
- │ │ CodeExecutionService │ │
355
- │ │ │ │
356
- │ │ ┌──────────────────────┐ │ │
357
- │ │ │ WorkerPool │ │ │
358
- │ │ │ - Queue Requests │ │ │
359
- │ │ │ - Monitor Health │ │ │
360
- │ │ │ - Auto Restart │ │ │
361
- │ │ └──────────────────────┘ │ │
362
- │ └────────────────────────────┘ │
363
- │ │ │ │
364
- └──────────┼──────────┼───────────────┘
365
- │ │ IPC (JSON)
366
- ┌──────▼───┐ ┌───▼──────┐
367
- │ Worker 1 │ │ Worker 2 │ (Separate OS Processes)
368
- │ │ │ │
369
- │ isolated │ │ isolated │
370
- │ -vm │ │ -vm │
371
- │ │ │ │
372
- └──────────┘ └──────────┘
457
+ const values = input.measurements;
458
+ output = {
459
+ mean: math.mean(values),
460
+ median: math.median(values),
461
+ std: math.std(values),
462
+ variance: math.variance(values),
463
+ min: math.min(values),
464
+ max: math.max(values)
465
+ };
466
+ `,
467
+ language: 'javascript',
468
+ inputData: {
469
+ measurements: [23.1, 24.5, 22.8, 25.0, 23.7, 24.2, 22.9]
470
+ }
471
+ });
373
472
  ```
374
473
 
375
- ### Benefits of Process Isolation
474
+ ## Best Practices
376
475
 
377
- - **Fault Tolerance**: Worker crashes don't affect main app or other workers
378
- - **Resource Isolation**: Per-process memory limits and cleanup
379
- - **Automatic Recovery**: Crashed workers restart automatically
380
- - **Circuit Breaker**: Too many crashes → worker disabled to prevent crash loops
476
+ 1. **Initialize Once**: Create a single `CodeExecutionService` instance and reuse it across your application. The worker pool is shared and handles concurrency internally.
477
+ 2. **Shutdown Gracefully**: Call `service.shutdown()` during application shutdown to terminate workers cleanly and reject pending requests.
478
+ 3. **Set Appropriate Timeouts**: Adjust `timeoutSeconds` based on expected workload. Short timeouts (5-10s) for simple calculations, longer (30-60s) for complex data processing.
479
+ 4. **Validate Input Data**: Ensure input data is JSON-serializable and in the expected format before execution. All data crosses an IPC boundary via JSON serialization.
480
+ 5. **Check Result Success**: Always check `result.success` before accessing `result.output`. Errors are returned in the result object, not thrown as exceptions.
481
+ 6. **Monitor Pool Health**: Use `service.getStats()` to monitor worker health and queue depth in production.
482
+ 7. **Use Console Logging**: Add `console.log()` statements in sandbox code for debugging. Output is captured in `result.logs`.
483
+ 8. **Leverage Libraries**: Use the provided allowlisted libraries (lodash, date-fns, mathjs, etc.) rather than reimplementing common operations.
484
+ 9. **Keep Code Synchronous**: The sandbox does not support `async/await` or Promises. All code must be synchronous.
485
+
486
+ ## Dependencies
487
+
488
+ | Package | Purpose |
489
+ |---------|---------|
490
+ | `@memberjunction/core` | MJ core framework (logging via `LogError`, `LogStatus`) |
491
+ | `@memberjunction/global` | MJ global utilities |
492
+ | `isolated-vm` | V8 isolate-based sandboxing (native module) |
493
+ | `lodash` | Source for inline lodash subset |
494
+ | `date-fns` | Source for inline date-fns subset |
495
+ | `mathjs` | Bundled for sandbox use |
496
+ | `papaparse` | Bundled for sandbox use |
497
+ | `uuid` | Source for inline UUID implementation |
498
+ | `validator` | Source for inline validator subset |
499
+
500
+ ## Related Packages
501
+
502
+ - [@memberjunction/core-actions](../CoreActions) - Pre-built actions including the "Execute Code" action that wraps this service
503
+ - [@memberjunction/actions-base](../Base) - Base classes for the Actions framework
504
+ - [@memberjunction/actions](../Engine) - Server-side action execution engine
381
505
 
382
506
  ## Limitations
383
507
 
384
- - **Language Support**: Currently only JavaScript (Python may be added in future)
385
- - **Async Code**: No support for `async/await` or Promises (synchronous code only)
386
- - **Library Expansion**: New libraries require code changes (not configurable at runtime)
387
- - **Throughput**: ~100-200 executions/sec per worker (horizontal scaling recommended for higher loads)
388
-
389
- ## Contributing
390
-
391
- This package is part of the MemberJunction project. See the main repository for contribution guidelines.
508
+ - **Language Support**: Currently only JavaScript. Python support may be added in the future.
509
+ - **Async Code**: No support for `async/await` or Promises. Sandbox code must be synchronous.
510
+ - **Library Expansion**: Adding new libraries requires code changes to the allowlist; they are not configurable at runtime.
511
+ - **Throughput**: Approximately 100-200 executions per second per worker. Use `poolSize` configuration or horizontal scaling for higher loads.
512
+ - **Data Size**: All input/output data crosses an IPC boundary via JSON serialization, so extremely large payloads may impact performance.
392
513
 
393
514
  ## License
394
515
 
395
- ISC
516
+ MIT
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerPool.d.ts","sourceRoot":"","sources":["../src/WorkerPool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CA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AM,SAAS,CAAC;AAoBnE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uEAAuE;IACvE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,YAAY,CAAwB;IAC5C,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,cAAc,CAAS;gBAEnB,OAAO,GAAE,iBAAsB;IAO3C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQjC;;OAEG;YACW,YAAY;IAiD1B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA0B3B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA8CzB;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAoDxE;;OAEG;IACH,OAAO,CAAC,YAAY;IAkCpB;;OAEG;IACH,QAAQ,IAAI;QACR,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;KACvB;IAYD;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAyClC"}
@@ -13,6 +13,9 @@
13
13
  */
14
14
  import { fork } from 'child_process';
15
15
  import * as path from 'path';
16
+ import { fileURLToPath } from 'node:url';
17
+ const __filename = fileURLToPath(import.meta.url);
18
+ const __dirname = path.dirname(__filename);
16
19
  import { LogError, LogStatus } from '@memberjunction/core';
17
20
  /**
18
21
  * Manages a pool of worker processes for code execution
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerPool.js","sourceRoot":"","sources":["../src/WorkerPool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,IAAI,EAAgB,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAiC3D;;GAEG;AACH,MAAM,OAAO,UAAU;IAUnB,YAAY,UAA6B,EAAE;QATnC,YAAO,GAAa,EAAE,CAAC;QACvB,iBAAY,GAAqB,EAAE,CAAC;QACpC,kBAAa,GAAG,CAAC,CAAC;QAKlB,mBAAc,GAAG,KAAK,CAAC;QAG3B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,IAAI,CAAC,CAAC;QAC5D,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC,CAAC,WAAW;QACpE,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,GAAG,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACZ,SAAS,CAAC,+CAA+C,GAAG,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC;QAExF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;IACL,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,YAAY,CAAC,EAAU;QACjC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@memberjunction/code-execution",
3
3
  "type": "module",
4
- "version": "4.0.0",
4
+ "version": "4.2.0",
5
5
  "description": "Sandboxed code execution service for MemberJunction actions and agents",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "watch": "tsc --watch"
11
11
  },
12
12
  "dependencies": {
13
- "@memberjunction/core": "4.0.0",
14
- "@memberjunction/global": "4.0.0",
13
+ "@memberjunction/core": "4.2.0",
14
+ "@memberjunction/global": "4.2.0",
15
15
  "isolated-vm": "^6.0.2",
16
16
  "lodash": "^4.17.23",
17
17
  "date-fns": "^3.0.0",
package/src/WorkerPool.ts CHANGED
@@ -14,6 +14,10 @@
14
14
 
15
15
  import { fork, ChildProcess } from 'child_process';
16
16
  import * as path from 'path';
17
+ import { fileURLToPath } from 'node:url';
18
+
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ const __dirname = path.dirname(__filename);
17
21
  import { CodeExecutionParams, CodeExecutionResult } from './types';
18
22
  import { LogError, LogStatus } from '@memberjunction/core';
19
23