(options: CodeInterpreterOptions = {})
| 43 | * @returns A CodeInterpreter instance |
| 44 | */ |
| 45 | export async function createSandbox(options: CodeInterpreterOptions = {}): Promise<CodeInterpreter> { |
| 46 | const apiKey = options.apiKey || Deno.env.get("E2B_API_KEY"); |
| 47 | if (!apiKey) { |
| 48 | throw new Error("E2B_API_KEY is required either in options or as an environment variable"); |
| 49 | } |
| 50 | |
| 51 | try { |
| 52 | // Create a real E2B Code Interpreter instance |
| 53 | const interpreter = new CodeInterpreter({ apiKey }); |
| 54 | await logMessage("info", "Created code interpreter sandbox"); |
| 55 | return interpreter; |
| 56 | } catch (error: unknown) { |
| 57 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 58 | await logMessage("error", "Failed to create code interpreter sandbox", { error: errorMessage }); |
| 59 | throw error; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Execute code in the sandbox |
no test coverage detected