Name and label miniVMs
A miniVM can have a name and labels. Both are optional.
- A name says what the miniVM is for, for example
fix-flaky-cache-test. You see it inons lsnext to the id.ons lslists only the miniVMs your API key created. - Labels are
key=valuepairs, for exampletask=cache-fixorteam=red. A script or an orchestrating agent lists the miniVMs that carry a label and acts on them.
We recommend that you name every miniVM you create and give it a task label. Nothing requires it.
| Name | Labels | |
|---|---|---|
| How many | At most one. | At most 16 per miniVM. |
| Length | 1 to 64 characters. | Key: 1 to 63 characters. Value: at most 128 characters. |
| Characters | Characters that show as themselves: no control or invisible characters, no leading or trailing whitespace. | Key: letters, digits, ., _, - and /, starting with a letter or a digit. Value: visible ASCII, no spaces. |
| Unique | No. Two miniVMs can have the same name. | No. |
Labels follow the same rules as agent run labels. A create or a change that breaks a rule is refused with 400, and the message names the rule broken.
Set them at create
Section titled “Set them at create”With ons:
ons create --name fix-flaky-cache-test --label task=cache-fix --label team=red--namesets the name.--label <key>=<value>adds a label; repeat it for each one.- With
--count, every miniVM of the batch gets the same name and labels.
With the API:
curl -s https://api.onshore.sh/v2/sandboxes \ -H "X-API-Key: $ONS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"templateID": "base", "timeout": 600, "name": "fix-flaky-cache-test", "labels": {"task": "cache-fix", "team": "red"}}'ONS_API_KEYis an environment variable that holds your onshore.sh API key.POST /v1/sandboxes/batchtakesnameandlabelstoo, and gives every miniVM of the batch the same values.
With the E2B SDKs
Section titled “With the E2B SDKs”The E2B SDKs have no name or label field, so onshore.sh reads two metadata keys:
from e2b import Sandbox
sbx = Sandbox.create(metadata={"name": "fix-flaky-cache-test", "msb.label.task": "cache-fix"})print(sbx.get_info().metadata)import { Sandbox } from 'e2b'
const sbx = await Sandbox.create({ metadata: { name: 'fix-flaky-cache-test', 'msb.label.task': 'cache-fix' } })console.log((await sbx.getInfo()).metadata)Set E2B_DOMAIN=onshore.sh and E2B_API_KEY before you run them. See Migrate from E2B.
- Metadata
namebecomes the miniVM’s name when it passes the name rule. Otherwise it stays plain metadata and the miniVM has no name (control or format characters, such as zero-width ones, are refused with400, as in any metadata). - Metadata
msb.label.<key>becomes the label<key>. An invalid one is refused with400. A metadata key cannot hold/, so a label key with/needs the API’slabelsfield orons. - Both keys also stay in the metadata.
get_info().metadata(getInfo()in JavaScript) reads them back as you sent them, and the metadata filter ofSandbox.liststill finds the miniVM. After a rename, the metadata follows the new name and labels. - You can give the name or a label both as a field and as a metadata key. With the same value, that is fine. With different values, the create is refused with
400:name set twice (field "name" and metadata "name") with different values · send one(the same for a label). The 16-label limit counts the labels of both together.
Agent runs
Section titled “Agent runs”ons agent new and ons agent start --template create a miniVM for the run: --name names that miniVM, and --label labels both the run and that miniVM. On an existing miniVM, --label labels the run only; label the miniVM with ons label set (below). Run labels are covered in Agent runs.
Change them later
Section titled “Change them later”You can change the name and labels of a miniVM that has not ended, running or paused.
ons rename <minivm-id> review-cache-fixons rename <minivm-id> --clearons label set <minivm-id> task=cache-review stage=reviewons label rm <minivm-id> stage<minivm-id>is the idons createprinted (ons lslists yours).ons rename --clearremoves the name.ons label setadds or changes the labels you give. The other labels stay.ons label rmremoves the labels with these keys. A key the miniVM does not have is ignored.- Each command prints the updated miniVM, as
ons lsdoes. With--json, it prints the same object asons inspect --json.
With the API, send a JSON merge patch to PATCH /v1/sandboxes/<minivm-id>:
curl -s -X PATCH https://api.onshore.sh/v1/sandboxes/<minivm-id> \ -H "X-API-Key: $ONS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"name": "review-cache-fix", "labels": {"stage": "review", "team": null}}'- A string sets the name or a label.
nullclears the name or removes a label."labels": nullremoves every label. A field or label you leave out is kept. - The answer is
200with the updated miniVM, as the list returns it. {}, with nothing to change, is refused with400. So is a change that leaves more than 16 labels.- Only the API key that created the miniVM can change it, as with pause and kill. Another key gets
404, as for an unknown id. Code inside the miniVM, with its self token, gets403: a miniVM cannot rename or relabel itself. - A miniVM that has ended answers
409: its name and labels are read-only.
List and filter
Section titled “List and filter”ons ls shows a NAME and a LABELS column (- when empty). ons inspect <minivm-id> shows the same row.
ons ls --label task=cache-fixons ls --label team=red --label task=cache-fixons ls --json --label task=cache-fix--label <key>=<value>keeps only the miniVMs with that label. Repeat it: every label must match.- With
--json, every item hasname(a string, ornull) andlabels(an object,{}when empty). - The text columns of
ons lschanged with names and labels. Scripts should read--json.
With the API, add label=<key>=<value> to GET /v2/sandboxes, once per label:
curl -s "https://api.onshore.sh/v2/sandboxes?label=task=cache-fix&label=team=red" \ -H "X-API-Key: $ONS_API_KEY"- Every label must match. The same key twice with different values is refused with
400. label=combines withmetadata,state,templateand paging.label=matches labels only: free metadatatask=cache-fixdoes not matchlabel=task=cache-fix.- Every item carries
nameandlabels.
A key lists only the miniVMs it created, with or without a label filter.
In the console, Fleet shows each miniVM’s name and labels. Click a label to list only the miniVMs that carry it. Click others to combine them: every label must match. Remove a filter from the bar above the list. The filters are kept in the page’s link, so you can share a filtered view.
Who sees what
Section titled “Who sees what”| Who can see it | |
|---|---|
| Name and labels | The API key that created the miniVM, and every member of your organization while the miniVM is running or paused. |
| Free metadata | Only the API key that created the miniVM. |
Retention
Section titled “Retention”A miniVM that ended keeps its name and labels, read-only, as long as the rest of its record: your organization’s run data retention, 90 days after the miniVM ended (see Data handling). Until then, the API list shows them for ended miniVMs with state=killed. After that, they are deleted with the record.