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

Function wrapAsSandboxModule

packages/ai-isolate-cloudflare/src/worker/index.ts:71–82  ·  view source on GitHub ↗

* Wrap the existing IIFE-returning string in an ES module that exposes a * `fetch` handler. The child Worker's entrypoint runs the IIFE on each * invocation and returns the structured result as JSON.

(wrappedCode: string)

Source from the content-addressed store, hash-verified

69 * invocation and returns the structured result as JSON.
70 */
71function wrapAsSandboxModule(wrappedCode: string): string {
72 return `
73export default {
74 async fetch() {
75 const __result = await ${wrappedCode};
76 return new Response(JSON.stringify(__result), {
77 headers: { 'Content-Type': 'application/json' },
78 });
79 }
80};
81`
82}
83
84/**
85 * Execute code in a freshly loaded child Worker isolate.

Callers 1

executeCodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected