Example: List and cleanup
You use this pattern when you operate dashboards, janitor cron jobs, or cost controls. You calllistSandboxes / 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 walkpage 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:ListSandboxesMetawithtotal_pages(snake_case). - Removal:
removeSandbox(id)on the client, orsandbox.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 untilpage > 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.Step 4: Delete with error isolation
You continue the sweep when oneremove fails (network blip).
Practices you should follow
- You use
refIdornameconventions 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.
Related guides
Lifecycle
Pause, resume, sleep semantics
TypeScript SDK
listSandboxes return shape
