You get an alert: a sandbox made 400 outbound requests that were refused. Its ID is sbx_.... Which agent started it? For which ticket? Is anyone still waiting on it? Can you stop it? If the only identifier you have is the sandbox ID, answering those takes a search through several systems. If the sandbox carries the right labels, it takes one lookup.

This post is a small, opinionated labelling scheme for agent sandboxes, and the code to make it impossible to forget.

The labels

Keep the set small and always present. These seven cover most questions:

Label Example Answers
task tsk_7f3a Which unit of agent work is this?
ticket PAY-1423 Which issue or request asked for it?
pr web#812 Which pull request did it produce or test?
agent claude-code Which agent or integration started it?
started_by maya Which person is responsible?
cost_owner team-payments Who pays for it?
env ci, prod, dev What kind of run is it?

Rules that keep labels useful:

  • Values are identifiers, not prose. PAY-1423, not "fix the payment bug".
  • Never put secrets or personal data in labels. They are shown in lists, logs and exports.
  • Same keys everywhere. Pick names once and use them in your logs and metrics too, so you can join on them.

Enforce them in one wrapper

Labels that depend on each call site remembering them will be missing exactly when you need them. Put creation behind one function that requires them:

import { Sandscale } from '@sandscale/sdk'; const sandscale = new Sandscale(); type RunContext = { task: string; ticket?: string; pr?: string; agent: string; startedBy: string; costOwner: string; env: 'ci' | 'prod' | 'dev'; }; export async function createRunSandbox(ctx: RunContext, template = 'builtin:python') { const labels: Record<string, string> = { task: ctx.task, agent: ctx.agent, started_by: ctx.startedBy, cost_owner: ctx.costOwner, env: ctx.env, }; if (ctx.ticket) labels.ticket = ctx.ticket; if (ctx.pr) labels.pr = ctx.pr; return sandscale.sandboxes.create({ template, timeoutSeconds: 30 * 60, labels }); } 

Now the type checker refuses a sandbox without a task, an agent, a person and a cost owner. Lint against direct calls to sandboxes.create elsewhere in the codebase if you want to be strict.

Put the sandbox ID back where people look

Traceability runs both ways. When the agent comments on the ticket or opens the PR, include the sandbox ID and task ID in the body or a footer. A reviewer looking at a strange change can then go straight to the run that produced it.

Queries this makes possible

With labels on every box, everyday questions become list filters:

const { data } = await sandscale.sandboxes.list({ status: 'running' }); // what is running for one ticket? const forTicket = data.filter((s) => s.labels?.ticket === 'PAY-1423'); // what has the CI agent left running for more than an hour? const stale = data.filter( (s) => s.labels?.env === 'ci' && s.createdAt && Date.now() - s.createdAt.getTime() > 3_600_000, ); 

And in your own logs and cost reports, group by cost_owner and agent to see who is spending what, which feeds directly into spend caps.

Labels, projects and the audit log

Labels are for your own grouping and lookup. Two other layers do different jobs:

  • Projects separate work with their own policy and quotas. On Sandscale, metadata.project_id on create runs the sandbox in a project; projects come with Team and Enterprise.
  • The audit log records who did what, independently of your labels, in a form where edits and gaps show. On Sandscale it is hash-chained and on every plan, with export on Team and up.

Use labels to find things fast, projects to separate teams or customers, and the audit log as the record you trust when the other two disagree. Our posts on what an audit log for coding agents should record and structured logging for agent runs cover the other two layers.

The incident version

Back to the alert. With this scheme, the response is: look up the sandbox, read task, ticket, agent and started_by, stop it if nothing should be running, message the person, and open the audit log filtered to that sandbox to see what it did. Most of it is reading. Without labels, it is an investigation.

Originally published on the Sandscale blog.