# Tracing a sandbox back to the ticket: labels, metadata and run records for agent work

> When a box does something unexpected, the first question is what it belonged to. A labelling scheme for agent sandboxes (task, ticket, PR, agent, user, cost owner), how to enforce it in one wrapper, and the queries it makes possible.

When a box does something unexpected, the first question is what it belonged to. A labelling scheme for agent sandboxes (task, ticket, PR, agent, user, cost owner), how to enforce it in one wrapper, and the queries it makes possible.

November 26, 2026 · 3 min read · The Sandscale team

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:

```ts
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:

```ts
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](https://sandscale.dev/blog/spend-caps-for-ai-agents).

## 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](https://sandscale.dev/blog/audit-log-for-ai-coding-agents) and [structured logging for agent runs](https://sandscale.dev/blog/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.

**On this page**

1. The labels
2. Enforce them in one wrapper
3. Put the sandbox ID back where people look
4. Queries this makes possible
5. Labels, projects and the audit log
6. The incident version

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [November 26, 2026 · **30 questions to ask any agent sandbox provider before you sign up** · A vendor-neutral checklist for choosing where your agents run code: isolation, network, secrets, lifecycle, billing for waiting time, governance, data location, reliability and leaving. With where to find each answer for Sandscale.](https://sandscale.dev/blog/questions-to-ask-an-agent-sandbox-provider)
- [November 26, 2026 · **Agent sandbox glossary: 41 terms in plain English** · Plain definitions for the words that come up when you run AI agent code in isolation: microVM, VMM, KVM, jailer, gVisor, seccomp, namespaces, egress allowlist, lease, snapshot, warm pool, awake vCPU-hour and more.](https://sandscale.dev/blog/agent-sandbox-glossary)

---
Source: https://sandscale.dev/blog/labels-and-run-records-for-traceability
