You can list sandboxes using the Sandbox.list() method.
Please note that methods related to “getting sandbox list” in the beta SDK have significant updates. For details, please refer to Changes in the Beta SDKs.
Once you have information about running sandbox, you can connect to it using the Sandbox.connect() method.
Copy
Ask AI
import { Sandbox } from '@e2b/code-interpreter'// Create a sandbox.const sandbox = await Sandbox.create({ metadata: { name: 'My Sandbox', },})// List all running sandboxes.const runningSandboxes = await Sandbox.list()const runningSandbox = runningSandboxes[0]console.log('Running sandbox metadata:', runningSandbox.metadata)console.log('Running sandbox id:', runningSandbox.sandboxId)console.log('Running sandbox started at:', runningSandbox.startedAt)console.log('Running sandbox template id:', runningSandbox.templateId)// Example output:// Running sandbox metadata: { name: 'My Sandbox' }// Running sandbox id: iqbeb0ag4drozc5ftytj5-a402f90a// Running sandbox started at: 2025-06-30T06:44:31.647Z// Running sandbox template id: 23j9hy90m6r461w7nkrn
The Sandbox.list() method now supports pagination. In the advanced pagination section, you can find more information about pagination techniques using the updated method.
Copy
Ask AI
import { Sandbox, SandboxInfo } from '@e2b/code-interpreter'const sandbox = await Sandbox.create()const paginator = Sandbox.list()// Get the first page of sandboxes (running and paused)const firstPage = await paginator.nextItems()// Get the next page of sandboxesconst nextPage = await paginator.nextItems()
Filter sandboxes by their current state. The state parameter can contain either “running” for running sandboxes or “paused” for paused sandboxes, or both.
Copy
Ask AI
import { Sandbox } from '@e2b/code-interpreter'// Create a sandbox.const sandbox = await Sandbox.create()// List all sandboxes that are running or paused.const paginator = Sandbox.list({ query: { state: ['running', 'paused'], },})const sandboxes = await paginator.nextItems()
Filter sandboxes by the metadata key value pairs specified during Sandbox creation.
Copy
Ask AI
import { Sandbox } from '@e2b/code-interpreter'// Create sandbox with metadata.const sandbox = await Sandbox.create({ metadata: { env: 'dev', app: 'my-app', userId: '123', },})// List all sandboxes that has `userId` key with value `123` and `env` key with value `dev`.const paginator = Sandbox.list({ query: { metadata: { userId: '123', env: 'dev' }, },})const sandboxes = await paginator.nextItems()
For more granular pagination, you can set custom per-page item limit (default and maximum is 1000) and specify an offset parameter (nextToken or next_token) to start paginating from.
Copy
Ask AI
import { Sandbox } from '@e2b/code-interpreter'const paginator = Sandbox.list({ limit: 1000, nextToken: '<base64-encoded-token>',})// Additional paginator properties// Whether there is a next pagepaginator.hasNext// Next page tokenpaginator.nextToken// Fetch the next pageawait paginator.nextItems()
You can fetch all pages by looping through the paginator while checking if there is a next page (using hasNext or has_next property) and fetching until there are no more pages left to fetch:
Copy
Ask AI
import { Sandbox } from '@e2b/code-interpreter'const paginator = Sandbox.list()// Loop through all pagesconst sandboxes: SandboxInfo[] = []while (paginator.hasNext) { const items = await paginator.nextItems() sandboxes.push(...items)}