MCPcopy Create free account
hub / github.com/TanStack/ai / runInIsolate

Function runInIsolate

packages/ai-isolate-quickjs/tests/escape-attempts.test.ts:4–27  ·  view source on GitHub ↗
(
  code: string,
  opts?: { timeout?: number },
)

Source from the content-addressed store, hash-verified

2import { createQuickJSIsolateDriver } from '../src/isolate-driver'
3
4async function runInIsolate(
5 code: string,
6 opts?: { timeout?: number },
7): Promise<{
8 success: boolean
9 value: unknown
10 error?: { name: string; message: string }
11}> {
12 const driver = createQuickJSIsolateDriver()
13 const context = await driver.createContext({
14 bindings: {},
15 ...(opts?.timeout !== undefined && { timeout: opts.timeout }),
16 })
17 try {
18 const res = await context.execute(code)
19 return {
20 success: res.success,
21 value: res.value,
22 ...(res.error !== undefined && { error: res.error }),
23 }
24 } finally {
25 await context.dispose()
26 }
27}
28
29describe('QuickJS isolate — sandbox escape attempts', () => {
30 it('does not expose `process`', async () => {

Callers 1

Calls 3

executeMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected