(options: CodeInterpreterOptions = {})
| 48 | * @returns A promise that resolves to the sandbox instance |
| 49 | */ |
| 50 | export async function createSandbox(options: CodeInterpreterOptions = {}): Promise<Sandbox> { |
| 51 | const apiKey = options.apiKey || Deno.env.get("E2B_API_KEY"); |
| 52 | if (!apiKey) { |
| 53 | throw new Error("E2B_API_KEY is required either in options or as an environment variable"); |
| 54 | } |
| 55 | |
| 56 | try { |
| 57 | // Create a new sandbox instance using the factory method |
| 58 | // @ts-ignore - Ignore TypeScript errors for API compatibility |
| 59 | const sandbox = await Sandbox.create({ apiKey }); |
| 60 | console.log("Created code interpreter sandbox"); |
| 61 | return sandbox; |
| 62 | } catch (error: unknown) { |
| 63 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 64 | console.error("Failed to create code interpreter sandbox:", errorMessage); |
| 65 | throw error; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Execute code in the sandbox |
no test coverage detected