You can assign metadata to your sandbox. This metadata will be available if you call Sandbox.list(). This can be useful in a situation where each of your users have dedicated sandbox and the time between the steps of the integration is long. You can use the metadata to store the user id and reconnect to it later.
Copy
Ask AI
import { Sandbox } from 'e2b'const sandbox = await Sandbox.create({ template: 'base', metadata: { userID: 'uniqueID' }})// Keep the sandbox alive for 60 secondsawait sandbox.keepAlive(60_000)// You can even close the script// Later, can be even from another process// List all running sandboxesconst paginator = Sandbox.list({ query: {state: ['running']}})const runningSandboxes = await paginator.nextItems()// Find the sandbox by metadataconst found = runningSandboxes.find(s => s.metadata?.userID === 'uniqueID')if (found) { // Sandbox found, we can reconnect to it const sandbox = await Sandbox.reconnect(found.sandboxID)} else { // Sandbox not found}await sandbox.close()