|
10 | 10 | * This is the most secure sandbox option available in Node.js. |
11 | 11 | * |
12 | 12 | * NOTE: isolated-vm is an optionalDependency. If it fails to compile |
13 | | - * (e.g., on some CI runners), NCP will gracefully fall back to other |
| 13 | + * (e.g., on some CI runners), NCP will gracefully falls back to other |
14 | 14 | * sandbox options (Subprocess, Worker Thread, or VM). |
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import { logger } from '../../utils/logger.js'; |
18 | 18 |
|
19 | | -// Type-only import to avoid runtime errors when isolated-vm is not available |
20 | | -type IVM = typeof import('isolated-vm'); |
21 | | -type Isolate = import('isolated-vm').Isolate; |
22 | | -type Context = import('isolated-vm').Context; |
23 | | -type Reference<T> = import('isolated-vm').Reference<T>; |
24 | | -type Callback = import('isolated-vm').Callback; |
25 | | - |
26 | | -// Dynamically load isolated-vm at runtime (optional dependency) |
27 | | -let ivm: IVM | null = null; |
| 19 | +// Optional isolated-vm module |
| 20 | +let ivm: any = null; |
28 | 21 | let ivmLoadError: Error | null = null; |
29 | 22 |
|
30 | | -// Try to load isolated-vm module |
| 23 | +// Try to load isolated-vm module at runtime |
31 | 24 | (async () => { |
32 | 25 | try { |
33 | 26 | ivm = await import('isolated-vm'); |
@@ -155,7 +148,7 @@ export class IsolatedVMSandbox { |
155 | 148 |
|
156 | 149 | // Copy result out of isolate |
157 | 150 | const result = typeof resultRef === 'object' && resultRef !== null |
158 | | - ? await (resultRef as Reference<unknown>).copy() |
| 151 | + ? await resultRef.copy() |
159 | 152 | : resultRef; |
160 | 153 |
|
161 | 154 | const duration = Date.now() - startTime; |
@@ -193,8 +186,8 @@ export class IsolatedVMSandbox { |
193 | 186 | * Set up logging in the isolated context |
194 | 187 | */ |
195 | 188 | private async setupLogging( |
196 | | - context: Context, |
197 | | - jail: Reference<Record<string, unknown>>, |
| 189 | + context: any, |
| 190 | + jail: any, |
198 | 191 | logs: string[] |
199 | 192 | ): Promise<void> { |
200 | 193 | if (!ivm) throw new Error('isolated-vm not loaded'); |
@@ -240,8 +233,8 @@ export class IsolatedVMSandbox { |
240 | 233 | * Set up tool callbacks in the isolated context |
241 | 234 | */ |
242 | 235 | private async setupToolCallbacks( |
243 | | - context: Context, |
244 | | - jail: Reference<Record<string, unknown>>, |
| 236 | + context: any, |
| 237 | + jail: any, |
245 | 238 | tools: IsolatedVMTool[], |
246 | 239 | toolExecutor: (toolName: string, params: unknown) => Promise<unknown> |
247 | 240 | ): Promise<void> { |
@@ -311,7 +304,7 @@ export class IsolatedVMSandbox { |
311 | 304 | /** |
312 | 305 | * Set up basic utilities in the isolated context |
313 | 306 | */ |
314 | | - private async setupUtilities(jail: Reference<Record<string, unknown>>): Promise<void> { |
| 307 | + private async setupUtilities(jail: any): Promise<void> { |
315 | 308 | // JSON, Promise, Array, Object, etc. are already available in V8 |
316 | 309 | // We just need to ensure they're accessible |
317 | 310 |
|
|
0 commit comments