Skip to content

feat: get sandbox by metadata filter#6

Merged
OndrejDrapalik merged 1 commit into
mainfrom
feat/get-sandbox-by-metadata
Jul 8, 2026
Merged

feat: get sandbox by metadata filter#6
OndrejDrapalik merged 1 commit into
mainfrom
feat/get-sandbox-by-metadata

Conversation

@OndrejDrapalik

Copy link
Copy Markdown
Contributor

What

Adds a Get By selector to the Sandbox → Get operation:

  • ID (default) — unchanged existing behavior
  • Metadata — retrieve the first sandbox matching a metadata filter (JSON object, keys combined with AND)

Why

Finding a persistent sandbox by metadata currently requires Get Many + a Code node:

const match = $input.all().find(
  (i) => i.json?.metadata?.purpose === 'my-agent' && i.json.state !== 'error'
);

This breaks once the sandbox falls outside the Get Many limit, and it's a lot of ceremony for "give me my sandbox". The API already supports server-side filtering via the metadata query parameter of GET /v2/sandboxes (same filter the JS SDK exposes as Sandbox.list({ query: { metadata } })) — the node just didn't expose it.

How

  • listSandboxes in client.ts now takes an options object ({ limit, metadata }) and serializes the metadata filter as URL-encoded key=value pairs joined with &, matching the SDK's encoding (verified against the live API).
  • Get-by-metadata lists with limit: 1 + the filter, then fetches the matched sandbox by ID, so the output shape is identical to Get by ID.
  • No match / empty filter → clear NodeOperationError.

Testing

  • pnpm test — 16/16 (5 new: get by ID routing, get by metadata, no match, empty filter, getMany limit passthrough)
  • pnpm typecheck, pnpm lint, pnpm build — all clean
  • Metadata query format verified against the production API (?metadata=purpose%3D... returns the exact matching sandbox; unknown value returns [])

Add a "Get By" selector to the Sandbox > Get operation so a sandbox can
be retrieved either by ID (existing behavior, still the default) or by a
metadata filter. The filter is applied server-side via the `metadata`
query parameter of `GET /v2/sandboxes` (keys and values URL-encoded,
combined with AND), so it no longer requires listing all sandboxes and
filtering in a Code node. The matched sandbox is then fetched by ID so
the output shape is identical to Get by ID.

listSandboxes now takes an options object ({ limit, metadata }) to make
room for the new query parameter.
@cla-bot cla-bot Bot added the cla-signed label Jul 8, 2026
@OndrejDrapalik OndrejDrapalik marked this pull request as ready for review July 8, 2026 14:59
@OndrejDrapalik OndrejDrapalik merged commit c721725 into main Jul 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants