Skip to content

Sandboxes list v2 #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Apr 15, 2025
Merged

Sandboxes list v2 #667

merged 42 commits into from
Apr 15, 2025

Conversation

mishushakov
Copy link
Member

@mishushakov mishushakov commented Apr 4, 2025

  • Implements /v2/sandboxes list with pagination
  • Updated Async/Sync Python SDK
  • Updated JavaScript SDK
  • Updated Tests
  • Updated API Clients
  • Updated docs

Example usage:

JavaScript

import { Sandbox } from '../../src'

async function listSandboxes() {
  // List first 100 sandboxes with specific query parameters
  const paginator = Sandbox.list({
    query: { metadata: { sandbox_type: 'test' } },
    state: ['running', 'paused'],
    limit: 100, // max limit
  })

  const sandboxes = await paginator.nextItems()

  // Print first 100 sandboxes
  for (const sbx of sandboxes) {
    console.log(sbx.sandboxId)
  }

  // Get next 100 sandboxes if there are more
  if (paginator.hasNext) {
    paginator.nextItems()
  }
}

async function paginateIterator() {
  const paginator = Sandbox.list({
    query: { metadata: { sandbox_type: 'test' } },
    state: ['running', 'paused'],
    limit: 100, // max limit
  })

  // Iterate through all sandboxes using the iterator
  while (paginator.hasNext) {
    const sandboxes = await paginator.nextItems()
  }
}

Python (Sync)

from e2b import Sandbox, SandboxListQuery

def list_sandboxes():
    paginator = Sandbox.list(
        query=SandboxListQuery(metadata={"sandbox_type": "test"}),
        state=["running", "paused"],
        limit=100, # max limit
    )

   sandboxes = paginator.next_items()

    # print first 100 sandboxes
    for sbx in sandboxes:
        print(sbx.sandbox_id)

    # get next 100 sandboxes
    if paginator.has_next:
        paginator.next_items()

def paginate_iterator():
    sandboxes_list = Sandbox.list(
        query=SandboxListQuery(metadata={"sandbox_type": "test"}),
        state=["running", "paused"],
        limit=100, # max limit
    )
    
    while paginator.has_next:
        sandboxes = paginator.next_items()

Python (Async)

from e2b import AsyncSandbox, SandboxListQuery

async def list_sandboxes():
    paginator = Sandbox.list(
        query=SandboxListQuery(metadata={"sandbox_type": "test"}),
        state=["running", "paused"],
        limit=100, # max limit
    )

   sandboxes = await paginator.next_items()

    # print first 100 sandboxes
    for sbx in sandboxes:
        print(sbx.sandbox_id)

    # get next 100 sandboxes
    if paginator.has_next:
        paginator.next_items()

async def paginate_iterator():
    sandboxes_list = Sandbox.list(
        query=SandboxListQuery(metadata={"sandbox_type": "test"}),
        state=["running", "paused"],
        limit=100, # max limit
    )
    
    while paginator.has_next:
        sandboxes = await paginator.next_items()

Copy link

changeset-bot bot commented Apr 4, 2025

🦋 Changeset detected

Latest commit: 0490f39

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@e2b/python-sdk Minor
e2b Minor
@e2b/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mishushakov mishushakov self-assigned this Apr 4, 2025
@mishushakov mishushakov added feature New feature or request docs Improvements or additions to documentation sdk Improvements or additions to SDKs cli Improvements or additions to CLI labels Apr 4, 2025
@mishushakov mishushakov marked this pull request as ready for review April 10, 2025 14:48
@mishushakov
Copy link
Member Author

ps. tests pass on local but CI on beta branch is not setup yet

@ValentaTomas
Copy link
Member

Please export the paginator types. I would also name the AsyncSandbox.list paginator AsyncSandboxPaginator to reduce ambivalency.

@ValentaTomas
Copy link
Member

Can you make it so that the next_token/nextToken on .list are exclusive with the query+limit(if the limit cannot be changed on subsequent calls).

@ValentaTomas
Copy link
Member

ValentaTomas commented Apr 14, 2025

@mishushakov Merge this into main and then rebase to beta.

@mishushakov
Copy link
Member Author

@ValentaTomas can't merge to main, because tests will fail (there's no persistence in prod SDK)

@mishushakov
Copy link
Member Author

mishushakov commented Apr 14, 2025

Please export the paginator types. I would also name the AsyncSandbox.list paginator AsyncSandboxPaginator to reduce ambivalency.

Export top-level? eg.

from e2b import AsyncSandboxPaginator

Can you make it so that the next_token/nextToken on .list are exclusive with the query+limit(if the limit cannot be changed on subsequent calls).

This will just paginate every sandbox before cursor timestamp disregarding the filter. The query and limit are not stored in the cursor, only sandboxId + timestamp. Right now, you cannot pass any parameters when you call .next_items()/.nextItems(). Or am I not understanding something? Feel free to give me a code example.

Copy link
Member

Export top-level? eg.

Yes, as in the example you provided.

Copy link
Member

ValentaTomas commented Apr 15, 2025

This will just paginate every sandbox before cursor timestamp disregarding the filter. The query and limit are not stored in the cursor, only sandboxId + timestamp. Right now, you cannot pass any parameters when you call .next_items()/.nextItems(). Or am I not understanding something? Feel free to give me a code example.

Oh, I mistunderstood then with query being part of the cursor. Ok, you can keep it as it is.

@ValentaTomas
Copy link
Member

@ValentaTomas can't merge to main, because tests will fail (there's no persistence in prod SDK)

Got it.

@ValentaTomas ValentaTomas removed the request for review from ben-fornefeld April 15, 2025 08:43
@mishushakov mishushakov merged commit 939fedb into beta Apr 15, 2025
1 of 2 checks passed
@mishushakov mishushakov deleted the sandboxes-list-v2 branch April 15, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Improvements or additions to CLI docs Improvements or additions to documentation feature New feature or request sdk Improvements or additions to SDKs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants