Skip to content

Commit 8a5df27

Browse files
committed
fix: use any types for isolated-vm to avoid TypeScript errors
Since isolated-vm is optional and may not be installed, we cannot use type-only imports (TypeScript still tries to resolve them). Instead, use 'any' types and runtime null checks. This allows the code to compile on CI runners where isolated-vm fails to build, while maintaining runtime safety through null checks. The code gracefully falls back to Subprocess/Worker/VM sandboxes when isolated-vm is unavailable.
1 parent 4bf2b4d commit 8a5df27

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

src/code-mode/sandbox/isolated-vm-sandbox.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,17 @@
1010
* This is the most secure sandbox option available in Node.js.
1111
*
1212
* 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
1414
* sandbox options (Subprocess, Worker Thread, or VM).
1515
*/
1616

1717
import { logger } from '../../utils/logger.js';
1818

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;
2821
let ivmLoadError: Error | null = null;
2922

30-
// Try to load isolated-vm module
23+
// Try to load isolated-vm module at runtime
3124
(async () => {
3225
try {
3326
ivm = await import('isolated-vm');
@@ -155,7 +148,7 @@ export class IsolatedVMSandbox {
155148

156149
// Copy result out of isolate
157150
const result = typeof resultRef === 'object' && resultRef !== null
158-
? await (resultRef as Reference<unknown>).copy()
151+
? await resultRef.copy()
159152
: resultRef;
160153

161154
const duration = Date.now() - startTime;
@@ -193,8 +186,8 @@ export class IsolatedVMSandbox {
193186
* Set up logging in the isolated context
194187
*/
195188
private async setupLogging(
196-
context: Context,
197-
jail: Reference<Record<string, unknown>>,
189+
context: any,
190+
jail: any,
198191
logs: string[]
199192
): Promise<void> {
200193
if (!ivm) throw new Error('isolated-vm not loaded');
@@ -240,8 +233,8 @@ export class IsolatedVMSandbox {
240233
* Set up tool callbacks in the isolated context
241234
*/
242235
private async setupToolCallbacks(
243-
context: Context,
244-
jail: Reference<Record<string, unknown>>,
236+
context: any,
237+
jail: any,
245238
tools: IsolatedVMTool[],
246239
toolExecutor: (toolName: string, params: unknown) => Promise<unknown>
247240
): Promise<void> {
@@ -311,7 +304,7 @@ export class IsolatedVMSandbox {
311304
/**
312305
* Set up basic utilities in the isolated context
313306
*/
314-
private async setupUtilities(jail: Reference<Record<string, unknown>>): Promise<void> {
307+
private async setupUtilities(jail: any): Promise<void> {
315308
// JSON, Promise, Array, Object, etc. are already available in V8
316309
// We just need to ensure they're accessible
317310

0 commit comments

Comments
 (0)