Operations
List, search, read, and label the sandboxes of a project.
Operations are the reads and updates made on resources that already exist. A list reads a scope page by page, and a get reads one resource by its identifier.
Operations on sandboxes work the same on every sandbox type, whether the sandbox is running or stopped. Each operation reaches only the sandboxes of one project, the project that owns the API key of the request.
Use an operation to find a sandbox, read its state, or change its labels after it is created. To create a sandbox, see Sandboxes, and to change its state, see Lifecycle.
List sandboxes
List sandboxes to see the sandboxes of a project with their IDs, names, and states. A paginated list returns a large collection in pages, and each page continues where the last one ended.
A list of sandboxes covers one project and returns its sandboxes one page at a time.
Use a list to find a sandbox whose ID you do not know, and search to filter by name, state, class, labels, or resources. To read your own writes, such as a sandbox created a moment ago, use get.
from daytona import Daytona
daytona = Daytona()
page = daytona.v2.list()
for sandbox in page.items:
print(sandbox.id, sandbox.name, sandbox.state)| Parameter | Description |
|---|---|
cursor | Continues from a previous page. Format: the next_cursor of a previous page |
limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const page = await daytona.v2.list()
for (const sandbox of page.items) {
console.log(sandbox.id, sandbox.name, sandbox.state)
}| Parameter | Description |
|---|---|
cursor | Continues from a previous page. Format: the nextCursor of a previous page |
limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
package main
import (
"context"
"fmt"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
page, err := client.List(ctx, nil)
if err != nil {
log.Fatal(err)
}
for _, sandbox := range page.Items {
fmt.Println(sandbox.ID(), sandbox.Name(), sandbox.State())
}
}| Parameter | Description |
|---|---|
Cursor | Continues from a previous page. Format: the NextCursor of a previous page |
Limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
daytona sandbox list| Flag | Description |
|---|---|
--cursor | Continues from a previous page. Format: the cursor that the previous page prints |
--limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
--region | Lists only the sandboxes in this region or a region inside it. Default: every region Value: earth, us, us-east, us-east-ash-1, us-east-bos-1, us-east-iad-1, or the ID of a BYOC region of the organizationExample: us-east-ash-1 |
curl 'https://api.daytona.com/sandboxes' \
--header 'Authorization: Bearer YOUR_API_KEY'| Field | Description |
|---|---|
cursor | Continues from a previous page. Format: the next_cursor of a previous page |
limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
Iterate over all sandboxes
Iterate over all sandboxes to read every sandbox of the project without handling page cursors. Iteration over a paginated list reads one page after another until no page remains.
Iteration over the sandboxes of a project yields the sandboxes of every page in turn, and it ends after the last page, when the server returns no cursor.
Use iteration when a script needs every sandbox of the project rather than one page. To find only some of them, search with filters instead.
from daytona import Daytona
daytona = Daytona()
for sandbox in daytona.v2.iter():
print(sandbox.id, sandbox.name, sandbox.state)import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
for await (const sandbox of daytona.v2.iter()) {
console.log(sandbox.id, sandbox.name, sandbox.state)
}package main
import (
"context"
"fmt"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
for sandbox, err := range client.ListAll(ctx, nil) {
if err != nil {
log.Fatal(err)
}
fmt.Println(sandbox.ID(), sandbox.Name(), sandbox.State())
}
}# Follow every page until the server returns no cursor
daytona sandbox list --all| Flag | Description |
|---|---|
--all | Follows every page until the last one. |
Search sandboxes
Search sandboxes to find the ones that match a text query or a set of filters. A search matches stored resources against the query and filters and returns them sorted, one page at a time.
A search of sandboxes covers the project in every region and reads an eventually consistent central index, not the sandboxes themselves. Deleted sandboxes are left out of the results.
Use a search to find sandboxes by text, or by their state, class, labels, or persistence. Filters combine with AND. A create, update, or delete becomes searchable about 2 to 3 seconds after it is committed, so a sandbox created a moment ago may be missing. To read your own writes, use get.
from daytona import Daytona
daytona = Daytona()
# Free text over name and image, or an exact sandbox id
page = daytona.v2.search(q="my-sandbox")
for sandbox in page.items:
print(sandbox.id, sandbox.name, sandbox.state)| Parameter | Description |
|---|---|
cursor | Continues from a previous page. Format: the next_cursor of a previous page with the same filters and sort |
limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
order | Sets the sort order. Default: descValue: asc or descExample: "asc" |
persistent | Filters by persistence. Value: True for persistent sandboxes, False for ephemeral ones |
q | Matches free text against the name and image, or one sandbox ID exactly. Example: "my-sandbox" |
sort | Sets the sort field. Default: created_atValue: created_at, updated_at, last_activity_at, name, cores, memory_mib, or disk_mibExample: "name" |
states | Filters by state. Format: one state or a list of states Value: queued, creating, starting, started, pausing, paused, stopping, stopped, destroying, destroyed, or errorExample: "started" |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
// Free text over name and image, or an exact sandbox id
const page = await daytona.v2.search({ q: 'my-sandbox' })
for (const sandbox of page.items) {
console.log(sandbox.id, sandbox.name, sandbox.state)
}| Parameter | Description |
|---|---|
cursor | Continues from a previous page. Format: the nextCursor of a previous page with the same filters and sort |
limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
order | Sets the sort order. Default: descValue: asc or descExample: 'asc' |
persistent | Filters by persistence. Value: true for persistent sandboxes, false for ephemeral ones |
q | Matches free text against the name and image, or one sandbox ID exactly. Example: 'my-sandbox' |
sort | Sets the sort field. Default: created_atValue: created_at, updated_at, last_activity_at, name, cores, memory_mib, or disk_mibExample: 'name' |
states | Filters by state. Format: one state or a list of states Value: queued, creating, starting, started, pausing, paused, stopping, stopped, destroying, destroyed, or errorExample: 'started' |
package main
import (
"context"
"fmt"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Free text over name and image, or an exact sandbox id
page, err := client.Search(ctx, &daytona.SearchSandboxesOptions{Q: "my-sandbox"})
if err != nil {
log.Fatal(err)
}
for _, sandbox := range page.Items {
fmt.Println(sandbox.ID(), sandbox.Name(), sandbox.State())
}
}| Parameter | Description |
|---|---|
Cursor | Continues from a previous page. Format: the NextCursor of a previous page with the same filters and sort |
Limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
Order | Sets the sort order. Default: daytona.SortOrderDescendingValue: daytona.SortOrderAscending or daytona.SortOrderDescendingExample: daytona.SortOrderAscending |
Persistent | Filters by persistence. Format: a pointer to a bool Value: true for persistent sandboxes, false for ephemeral ones |
Q | Matches free text against the name and image, or one sandbox ID exactly. Example: "my-sandbox" |
Sort | Sets the sort field. Default: daytona.SearchSortCreatedAtValue: daytona.SearchSortCreatedAt, daytona.SearchSortUpdatedAt, daytona.SearchSortLastActivityAt, daytona.SearchSortName, daytona.SearchSortCores, daytona.SearchSortMemoryMiB, or daytona.SearchSortDiskMiBExample: daytona.SearchSortName |
States | Filters by state. Format: a non-empty list of states Value: daytona.SandboxStateQueued, daytona.SandboxStateCreating, daytona.SandboxStateStarting, daytona.SandboxStateStarted, daytona.SandboxStatePausing, daytona.SandboxStatePaused, daytona.SandboxStateStopping, daytona.SandboxStateStopped, daytona.SandboxStateDestroying, daytona.SandboxStateDestroyed, or daytona.SandboxStateErrorExample: []daytona.SandboxState{daytona.SandboxStateStarted} |
# Free text over name and image, or an exact sandbox id
daytona sandbox search my-sandbox| Flag | Description |
|---|---|
<query> | Matches free text against the name and image, or one sandbox ID exactly. Example: my-sandbox |
--class | Filters by sandbox class. Format: a comma-separated list, or the flag repeated Value: linux or macosExample: linux |
--cursor | Continues from a previous page. Format: the cursor that a previous page with the same filters and sort prints |
--limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
--order | Sets the sort order. Default: descValue: asc or descExample: asc |
--persistent | Filters by persistence. Value: true for persistent sandboxes, false for ephemeral ones |
--sort | Sets the sort field. Default: created_atValue: created_at, updated_at, last_activity_at, name, cores, memory_mib, or disk_mibExample: name |
--status | Filters by API status. Format: a comma-separated list, or the flag repeated Value: queued, pending, assigned, booting, running, pausing, paused, stopping, stopped, deleting, deleted, failed, or lostExample: running |
# Free text over name and image, or an exact sandbox id
curl 'https://api.daytona.com/sandboxes/search?q=my-sandbox' \
--header 'Authorization: Bearer YOUR_API_KEY'| Field | Description |
|---|---|
cursor | Continues from a previous page. Format: the next_cursor of a previous page with the same filters and sort |
limit | Sets the page size. Default: 100Minimum: 1Maximum: 200 |
order | Sets the sort order. Default: descValue: asc or descExample: asc |
persistent | Filters by persistence. Value: true for persistent sandboxes, false for ephemeral ones |
q | Matches free text against the name and image, or one sandbox ID exactly. Example: my-sandbox |
sort | Sets the sort field. Default: created_atValue: created_at, updated_at, last_activity_at, name, cores, memory_mib, or disk_mibExample: name |
status | Filters by API status. Format: a comma-separated list Value: queued, pending, assigned, booting, running, pausing, paused, stopping, stopped, deleting, deleted, failed, or lostExample: running |
Iterate over search results
Iterate over search results to read every sandbox that a search matches without handling page cursors. Iteration over a paginated search reads one page after another until no page remains.
Iteration over a search of sandboxes takes the same filters, sort, and order as the search, and it ends after the last page, when the server returns no cursor. The results stay eventually consistent, as in a search.
Use iteration when a script needs every match rather than one page. To read every sandbox of the project without filters, iterate over all sandboxes instead.
from daytona import Daytona
daytona = Daytona()
# Follow every page of the search
for sandbox in daytona.v2.search_iter(q="my-sandbox"):
print(sandbox.id, sandbox.name, sandbox.state)| Parameter | Description |
|---|---|
q | Matches free text against the name and image, or one sandbox ID exactly. Example: "my-sandbox" |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
// Follow every page of the search
for await (const sandbox of daytona.v2.searchIter({ q: 'my-sandbox' })) {
console.log(sandbox.id, sandbox.name, sandbox.state)
}| Parameter | Description |
|---|---|
q | Matches free text against the name and image, or one sandbox ID exactly. Example: 'my-sandbox' |
package main
import (
"context"
"fmt"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Follow every page of the search
for sandbox, err := range client.SearchAll(ctx, &daytona.SearchSandboxesOptions{Q: "my-sandbox"}) {
if err != nil {
log.Fatal(err)
}
fmt.Println(sandbox.ID(), sandbox.Name(), sandbox.State())
}
}| Parameter | Description |
|---|---|
Q | Matches free text against the name and image, or one sandbox ID exactly. Example: "my-sandbox" |
# Follow every page until the server returns no cursor
daytona sandbox search my-sandbox --all| Flag | Description |
|---|---|
<query> | Matches free text against the name and image, or one sandbox ID exactly. Example: my-sandbox |
--all | Follows every page until the last one. |
Get a sandbox
Get a sandbox by its ID to read its current state, resources, labels, and lifecycle settings. A get reads one resource by its identifier and changes nothing on the server.
A get of a sandbox reads it from the control plane directly, not from the search index, so the result reflects a change as soon as the change is made.
Use a get to read a sandbox right after a change, which search can miss for a few seconds. Store the sandbox ID, or the sandbox data as JSON, to get the sandbox again later.
from daytona import Daytona
daytona = Daytona()
# Fetch the sandbox from the control plane
sandbox = daytona.v2.get("{sandboxId}")
print(sandbox.state, sandbox.cpu, sandbox.memory, sandbox.disk)
# Store the sandbox data as JSON; it carries no URL or credential
saved = sandbox.to_json() # {"sandboxId": "...", "name": "...", "state": "...", ...}
# Later, get the sandbox again by its ID
sandbox = daytona.v2.get(saved["sandboxId"])| Parameter | Description |
|---|---|
sandbox_id | Sets the sandbox to get. Required Format: a sandbox ID |
toolbox_url | Sets the URL that the sandbox sends its toolbox requests and its credential to, in place of the sandbox toolbox URL. Pass only a URL you control. Default: the sandbox toolbox URL Format: an HTTP or HTTPS URL without a query or fragment that already holds the sandbox ID, or that holds {sandbox_id} or {sandboxId} in its path, which the SDK replaces with the sandbox IDExample: "https://proxy.example.com/toolbox/{sandbox_id}" |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
// Fetch the sandbox from the control plane
const sandbox = await daytona.v2.get('{sandboxId}')
console.log(sandbox.state, sandbox.cpu, sandbox.memory, sandbox.disk)
// Store the sandbox data as JSON; it carries no URL or credential
const saved = sandbox.toJSON() // { sandboxId: '...', name: '...', state: '...', ... }
// Later, get the sandbox again by its ID
const again = await daytona.v2.get(saved.sandboxId)| Parameter | Description |
|---|---|
id | Sets the sandbox to get. Required Format: a sandbox ID |
toolboxUrl | Sets the URL that the sandbox sends its toolbox requests and its credential to, in place of the sandbox toolbox URL. Pass only a URL you control. Default: the sandbox toolbox URL Format: an HTTP or HTTPS URL without a query or fragment that already holds the sandbox ID, or that holds {sandboxId} or {sandbox_id} in its path, which the SDK replaces with the sandbox IDExample: 'https://proxy.example.com/toolbox/{sandboxId}' |
package main
import (
"context"
"fmt"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Fetch the sandbox from the control plane
sandbox, err := client.Get(ctx, "{sandboxId}", nil)
if err != nil {
log.Fatal(err)
}
info := sandbox.Info()
fmt.Println(info.State, info.Resources.CPU, info.Resources.MemoryGiB, info.Resources.DiskGiB)
// Store the sandbox data as JSON; it carries no URL or credential
saved := sandbox.ToJSON() // {SandboxID: "...", Name: "...", State: "...", ...}
// Later, get the sandbox again by its ID
sandbox, err = client.Get(ctx, saved.SandboxID, nil)
if err != nil {
log.Fatal(err)
}
}| Parameter | Description |
|---|---|
id | Sets the sandbox to get. Required Format: a sandbox ID |
ToolboxURL | Sets the URL that the sandbox sends its toolbox requests and its credential to, in place of the sandbox toolbox URL. Pass only a URL you control. Default: the sandbox toolbox URL Format: an HTTP or HTTPS URL without a query or fragment that already holds the sandbox ID, or that holds {sandboxId} or {sandbox_id} in its path, which the SDK replaces with the sandbox IDExample: "https://proxy.example.com/toolbox/{sandboxId}" |
daytona sandbox get {sandboxId}curl 'https://api.daytona.com/sandboxes/{sandboxId}' \
--header 'Authorization: Bearer YOUR_API_KEY'Refresh a sandbox
Refresh a sandbox to update a local object with the current data of the sandbox. A refresh replaces the fields that a client holds with the values the server holds now.
A refresh of a sandbox reads it from the control plane and updates the object in place. Until then, the object keeps the fields from the request that returned it, so its state, resources, and labels can be out of date after a change made by another client.
Refresh a sandbox before you act on its state or labels when another client may have changed them. Lifecycle operations such as start and stop refresh the object when they finish.
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create()
# Re-read the sandbox from the control plane
sandbox.refresh_data()
print(sandbox.state, sandbox.labels)import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create()
// Re-read the sandbox from the control plane
await sandbox.refreshData()
console.log(sandbox.state, sandbox.labels)package main
import (
"context"
"fmt"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
sandbox, err := client.Create(ctx, "", nil)
if err != nil {
log.Fatal(err)
}
// Re-read the sandbox from the control plane
if err := sandbox.Refresh(ctx); err != nil {
log.Fatal(err)
}
fmt.Println(sandbox.State(), sandbox.Info().Labels)
}Find sandboxes by name
Find sandboxes by name to look them up without their IDs. A name lookup returns every resource whose name matches exactly, because a name, unlike an ID, need not be unique.
The name of a sandbox is the name label it was created with. A sandbox whose labels no longer include the name label drops out of name lookups and of searches that filter on that label. The dashboard matches the start of a name, so it also lists sandboxes with longer names.
Find a sandbox by name to reuse it instead of creating a new one. The result is a list, newest first, and is empty when no sandbox matches. The lookup reads the search index, so a sandbox created a moment ago can be missing.
- Go to Daytona Sandboxes ↗
- Click the search match mode
- Select Name starts with
- Enter the sandbox name
from daytona import Daytona
daytona = Daytona()
# Reuse a named sandbox, or create it when none exists
found = daytona.v2.find_by_name("my-sandbox")
sandbox = found[0] if found else daytona.v2.create(name="my-sandbox")| Parameter | Description |
|---|---|
name | Matches the sandbox name exactly. Required Example: "my-sandbox" |
region | Limits the lookup to the sandboxes in this region or a region inside it. Default: every region Value: earth, us, us-east, us-east-ash-1, us-east-bos-1, us-east-iad-1, or the ID of a BYOC region of the organization, or "local" for every regionExample: "us-east-ash-1" |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
// Reuse a named sandbox, or create it when none exists
const found = await daytona.v2.findByName('my-sandbox')
const sandbox = found[0] ?? (await daytona.v2.create({ name: 'my-sandbox' }))| Parameter | Description |
|---|---|
name | Matches the sandbox name exactly. Required Example: 'my-sandbox' |
region | Limits the lookup to the sandboxes in this region or a region inside it. Default: every region Value: earth, us, us-east, us-east-ash-1, us-east-bos-1, us-east-iad-1, or the ID of a BYOC region of the organization, or 'local' for every regionExample: 'us-east-ash-1' |
package main
import (
"context"
"fmt"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Reuse a named sandbox, or create it when none exists
found, err := client.FindByName(ctx, "my-sandbox", nil)
if err != nil {
log.Fatal(err)
}
var sandbox *daytona.Sandbox
if len(found) > 0 {
sandbox = found[0]
} else {
sandbox, err = client.Create(ctx, "", &daytona.CreateOptions{Name: "my-sandbox"})
if err != nil {
log.Fatal(err)
}
}
fmt.Println(sandbox.ID())
}| Parameter | Description |
|---|---|
name | Matches the sandbox name exactly. Required Example: "my-sandbox" |
Region | Limits the lookup to the sandboxes in this region or a region inside it. Default: every region Value: earth, us, us-east, us-east-ash-1, us-east-bos-1, us-east-iad-1, or the ID of a BYOC region of the organization, or "local" for every regionExample: "us-east-ash-1" |
# Search by the name label: labels={"name":"my-sandbox"}
curl 'https://api.daytona.com/sandboxes/search?labels=%7B%22name%22%3A%22my-sandbox%22%7D' \
--header 'Authorization: Bearer YOUR_API_KEY'| Field | Description |
|---|---|
labels | Filters by labels that each sandbox must contain. Format: a URL-encoded JSON object of string keys and values Example: {"name":"my-sandbox"} |
Create an access token
Create an access token to give a person or program limited access to one sandbox. An access token is a short-lived credential that grants a fixed set of operations on one resource.
An access token of a sandbox works only for that sandbox, and only for the operations and private preview ports it grants. It lasts until it expires and cannot be refreshed or revoked. A client that holds it cannot use it to create other credentials.
Create an access token for a collaborator, CI job, or browser instead of a project API key. The token lasts one hour by default and at most 24 hours. Create a new one when it expires.
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create()
# Grant file system and SSH access for 15 minutes
token = sandbox.create_access_token(operations=["toolbox:fs", "ssh"], ttl_seconds=900)
print(token.access_token, token.expires_at)| Parameter | Description |
|---|---|
operations | Sets the operations that the token grants. Default: every operation that the API key can grant Value: any of toolbox, toolbox:exec, toolbox:fs, toolbox:git, desktop, ssh, sandbox:stop, sandbox:pause, and sandbox:delete, or [] for preview ports onlyExample: ["toolbox:fs", "ssh"] |
ports | Sets the private preview ports that the token can reach. Default: all ports Maximum: 128 ports Format: ports from 1 to 65535, except the sandbox daemon ports 2280, 2281, and 22220Value: [] for no portsExample: [3000] |
ttl_seconds | Sets the token lifetime in seconds. Default: 3600Minimum: 1Maximum: 86400 |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create()
// Grant file system and SSH access for 15 minutes
const token = await sandbox.createAccessToken({ operations: ['toolbox:fs', 'ssh'], ttlSeconds: 900 })
console.log(token.accessToken, token.expiresAt)| Parameter | Description |
|---|---|
operations | Sets the operations that the token grants. Default: every operation that the API key can grant Value: any of toolbox, toolbox:exec, toolbox:fs, toolbox:git, desktop, ssh, sandbox:stop, sandbox:pause, and sandbox:delete, or [] for preview ports onlyExample: ['toolbox:fs', 'ssh'] |
ports | Sets the private preview ports that the token can reach. Default: all ports Maximum: 128 ports Format: ports from 1 to 65535, except the sandbox daemon ports 2280, 2281, and 22220Value: [] for no portsExample: [3000] |
ttlSeconds | Sets the token lifetime in seconds. Default: 3600Minimum: 1Maximum: 86400 |
package main
import (
"context"
"fmt"
"log"
"time"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
sandbox, err := client.Create(ctx, "", nil)
if err != nil {
log.Fatal(err)
}
// Grant file system and SSH access for 15 minutes
token, err := sandbox.CreateAccessToken(ctx, &daytona.CreateAccessTokenOptions{
Operations: []string{"toolbox:fs", "ssh"},
TTL: 15 * time.Minute,
})
if err != nil {
log.Fatal(err)
}
fmt.Println(token.AccessToken, token.ExpiresAt)
}| Parameter | Description |
|---|---|
Operations | Sets the operations that the token grants. Default: every operation that the API key can grant Value: any of toolbox, toolbox:exec, toolbox:fs, toolbox:git, desktop, ssh, sandbox:stop, sandbox:pause, and sandbox:delete, or []string{} for preview ports onlyExample: []string{"toolbox:fs", "ssh"} |
Ports | Sets the private preview ports that the token can reach. Default: all ports Maximum: 128 ports Format: ports from 1 to 65535, except the sandbox daemon ports 2280, 2281, and 22220Value: []int{} for no portsExample: []int{3000} |
TTL | Sets the token lifetime. Default: time.HourMinimum: time.SecondMaximum: 24*time.HourFormat: a whole number of seconds |
# Grant file system and SSH access for 15 minutes
daytona sandbox access-token {sandboxId} --operations toolbox:fs,ssh --ttl 15m| Flag | Description |
|---|---|
--operations | Sets the operations that the token grants. Default: every operation that the API key can grant Format: a comma-separated list Value: any of toolbox, toolbox:exec, toolbox:fs, toolbox:git, desktop, ssh, sandbox:stop, sandbox:pause, and sandbox:delete, or none for preview ports onlyExample: toolbox:fs,ssh |
--ports | Sets the private preview ports that the token can reach. Default: all ports Maximum: 128 ports Format: a comma-separated list of ports from 1 to 65535, except the sandbox daemon ports 2280, 2281, and 22220Value: none for no portsExample: 3000 |
--ttl | Sets the token lifetime. Default: 1hMinimum: 1sMaximum: 24hFormat: a duration in whole seconds, such as 30s, 10m, or 1h |
# Grant file system and SSH access for 15 minutes
curl 'https://api.daytona.com/sandboxes/{sandboxId}/access-token' \
--request POST \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{"operations": ["toolbox:fs", "ssh"], "ttl_seconds": 900}'| Field | Description |
|---|---|
operations | Sets the operations that the token grants. Default: every operation that the API key can grant Value: any of toolbox, toolbox:exec, toolbox:fs, toolbox:git, desktop, ssh, sandbox:stop, sandbox:pause, and sandbox:delete, or [] for preview ports onlyExample: ["toolbox:fs", "ssh"] |
ports | Sets the private preview ports that the token can reach. Default: all ports Maximum: 128 ports Format: ports from 1 to 65535, except the sandbox daemon ports 2280, 2281, and 22220Value: [] for no portsExample: [3000] |
ttl_seconds | Sets the token lifetime in seconds. Default: 3600Minimum: 1Maximum: 86400 |
Label sandboxes
Label sandboxes to group them and find them again. Labels are key-value pairs that describe a resource, such as the team, environment, or run it belongs to.
The labels of a sandbox are stored with it as one set. A label update replaces the whole set, and it removes any label that is left out of the new label set.
Label sandboxes to filter them by key and value when you search. A sandbox holds at most 100 labels, and each key and each value holds at most 512 bytes.
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create()
# Replace the full label set
labels = sandbox.set_labels({"team": "research"})
print(labels)| Parameter | Description |
|---|---|
labels | Replaces the labels of the sandbox, except the name label when the new set omits it. Required Maximum: 100 labels Format: a non-empty key and a value of at most 512 bytes each Value: {} for no labels other than the name labelExample: {"team": "research"} |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create()
// Replace the full label set
const labels = await sandbox.setLabels({ team: 'research' })
console.log(labels)| Parameter | Description |
|---|---|
labels | Replaces the labels of the sandbox, except the name label when the new set omits it. Required Maximum: 100 labels Format: a non-empty key and a value of at most 512 bytes each Value: {} for no labels other than the name labelExample: { team: 'research' } |
package main
import (
"context"
"fmt"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
sandbox, err := client.Create(ctx, "", nil)
if err != nil {
log.Fatal(err)
}
// Replace the full label set
labels, err := sandbox.SetLabels(ctx, map[string]string{"team": "research"})
if err != nil {
log.Fatal(err)
}
fmt.Println(labels)
}| Parameter | Description |
|---|---|
labels | Replaces the labels of the sandbox, except the name label when the new set omits it. Required Maximum: 100 labels Format: a non-empty key and a value of at most 512 bytes each Value: nil for no labels other than the name labelExample: map[string]string{"team": "research"} |
# Replace the full label set
daytona sandbox update {sandboxId} --label team=research| Flag | Description |
|---|---|
--clear-labels | Removes every label except the name label. |
--label | Replaces the labels of the sandbox, except the name label when the new set omits it. Maximum: 100 labels Format: KEY=VALUE, a non-empty key and a value of at most 512 bytes each, with the flag repeated for each label Example: team=research |
# Replace the full label set
curl 'https://api.daytona.com/sandboxes/{sandboxId}/labels' \
--request PUT \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{ "labels": { "team": "research" } }'| Field | Description |
|---|---|
labels | Replaces the labels of the sandbox. Default: {}Maximum: 100 labels Format: a non-empty key and a value of at most 512 bytes each Value: {} for no labelsExample: {"team": "research"} |
Logs
Logs are the text output that a program or operating system writes as it runs. They show what happened inside a sandbox after the fact.
The logs of a sandbox are the output of its serial console, which records the boot of the operating system and the messages it prints. A follow reads new output as it is written, until it is interrupted.
Read the logs of a sandbox to find out why it failed to boot or stopped responding. Read them in the dashboard, or follow them from a terminal while the sandbox starts.
- Go to Daytona Sandboxes ↗
- Click the sandbox
- Open the Logs tab
- Open the Serial console tab
# Serial console log of the sandbox
daytona sandbox logs {sandboxId}
# Keep printing new output until interrupted
daytona sandbox logs {sandboxId} --follow| Flag | Description |
|---|---|
--entrypoint | Reads the entrypoint log instead of the serial console log. |
--follow | Polls for new log output until interrupted. |
# Serial console log of the sandbox
curl 'https://api.daytona.com/sandboxes/{sandboxId}/console-logs' \
--header 'Authorization: Bearer YOUR_API_KEY'Metrics
Metrics are measurements of how much CPU, memory, and disk is in use at one moment. They show whether a sandbox has spare capacity or is close to its limits.
- Go to Daytona Sandboxes ↗
- Click the sandbox
- Open the Metrics tab
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create()
metrics = sandbox.metrics()
print(metrics.cpu_utilization, metrics.memory_usage_bytes, metrics.disk_usage_bytes)import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create()
const metrics = await sandbox.metrics()
console.log(metrics.cpuUtilization, metrics.memoryUsageBytes, metrics.diskUsageBytes)package main
import (
"context"
"fmt"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
sandbox, err := client.Create(ctx, "", nil)
if err != nil {
log.Fatal(err)
}
metrics, err := sandbox.Metrics(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(metrics.CPUUtilization, metrics.MemoryUsageBytes, metrics.DiskUsageBytes)
}curl '{toolboxProxyUrl}/{sandboxId}/system/metrics' \
--header 'Authorization: Bearer YOUR_API_KEY'