To connect to a running sandbox, you first need to retrieve its ID. You can do this by calling the Sandbox.list() method.
Copy
Ask AI
import { Sandbox } from "@e2b/code-interpreter"// Get all running sandboxesconst runningSandboxes = await Sandbox.list()if (runningSandboxes.length === 0) { throw new Error("No running sandboxes found")}// Get the ID of the sandbox you want to connect toconst sandboxId = runningSandboxes[0].sandboxId
Now that you have the sandbox ID, you can connect to the sandbox using the Sandbox.connect() method.
Copy
Ask AI
import { Sandbox } from "@e2b/code-interpreter"// Get all running sandboxesconst runningSandboxes = await Sandbox.list()if (runningSandboxes.length === 0) { throw new Error("No running sandboxes found")}// Get the ID of the sandbox you want to connect toconst sandboxId = runningSandboxes[0].sandboxId// Connect to the sandboxconst sandbox = await Sandbox.connect(sandboxId)// Now you can use the sandbox as usual// ...