Skip to main content

Example: List and cleanup

You use this pattern when you operate dashboards, janitor cron jobs, or cost controls. You call listSandboxes / list_sandboxes with pagination, you inspect meta, you delete rows that match your policy with removeSandbox / remove_sandbox or sandbox.remove().

What you accomplish

You never assume “one page is everything.” You walk page until you cover meta.total. You delete only sandboxes your policy owns (for example names prefixed with tmp- or preview-). You handle API errors so one failure does not abort the entire sweep.

Concepts you use

  • TypeScript meta: total, page, limit, totalPages (camelCase).
  • Python meta: ListSandboxesMeta with total_pages (snake_case).
  • Removal: removeSandbox(id) on the client, or sandbox.remove() when you already hold the instance.

Prerequisites

You completed Examples overview.

Step 1: List the first page

Step 2: Walk every page

You loop until page > totalPages (TypeScript) or page > meta.total_pages (Python).

Step 3: Delete by naming policy

You match your prefix so you never delete unrelated org sandboxes.
You double-check prefix and org scope before you run destructive loops in production. You dry-run (log only) once after you change policy.

Step 4: Delete with error isolation

You continue the sweep when one remove fails (network blip).

Practices you should follow

  • You use refId or name conventions when you create sandboxes so cleanup stays deterministic.
  • You respect API rate limits: you sleep briefly between pages if your operator asks you to.
  • You read Lifecycle for pause / resume / sleep when you archive instead of delete.

Lifecycle

Pause, resume, sleep semantics

TypeScript SDK

listSandboxes return shape