| 20 | } |
| 21 | |
| 22 | async function runExample() { |
| 23 | console.log("Testing E2B SDK..."); |
| 24 | |
| 25 | try { |
| 26 | // Check if there's a default export that's a function |
| 27 | if (typeof e2b.default === 'function') { |
| 28 | console.log("Using e2b.default function"); |
| 29 | const result = await e2b.default({ apiKey }); |
| 30 | console.log("Result:", result); |
| 31 | } |
| 32 | // Check if Sandbox is a constructor |
| 33 | else if (typeof e2b.Sandbox === 'function') { |
| 34 | console.log("Using e2b.Sandbox constructor"); |
| 35 | try { |
| 36 | const sandbox = new e2b.Sandbox({ apiKey, sandboxId: "test" }); |
| 37 | console.log("Sandbox created:", sandbox); |
| 38 | } catch (error) { |
| 39 | console.error("Error creating sandbox:", error); |
| 40 | } |
| 41 | } |
| 42 | // Try other potential ways to use the SDK |
| 43 | else { |
| 44 | console.log("Trying other approaches..."); |
| 45 | |
| 46 | // Try to find any function that might be used to create a sandbox |
| 47 | const functionProps = Object.keys(e2b).filter(key => typeof e2b[key] === 'function'); |
| 48 | console.log("Available functions:", functionProps); |
| 49 | |
| 50 | for (const prop of functionProps) { |
| 51 | try { |
| 52 | console.log(`Trying e2b.${prop}...`); |
| 53 | const result = await e2b[prop]({ apiKey }); |
| 54 | console.log(`Result from e2b.${prop}:`, result); |
| 55 | break; |
| 56 | } catch (error) { |
| 57 | console.error(`Error using e2b.${prop}:`, error); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } catch (error: unknown) { |
| 62 | console.error("Error:", error instanceof Error ? error.message : String(error)); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // Run the example |
| 67 | runExample(); |