Lifecycle
The states of a sandbox and the actions that move it between them.
A sandbox lifecycle is the set of states that a sandbox moves through from creation to deletion. A sandbox changes state when a user acts on it, or on its own when a timeout elapses. The actions it accepts, and what it keeps across them, depend on its type.
A persistent sandbox can leave the running state and return to it with its disk, and on some sandbox types with its memory. An ephemeral sandbox cannot be stopped or paused to be used later. Timeouts act on a sandbox without a request, so a sandbox that is no longer used does not hold resources.
Act on a sandbox from the dashboard or in code, and set its timeouts when you create it. Wait for a state before a step that needs it, and check the table of each action for what each sandbox type supports.
| Lifecycle | Linux | Windows | macOS | GPU |
|---|---|---|---|---|
| Stop and start | ✓ | ✓ | ✓ | ✗ |
| Pause and resume | ✓ | ✗ | ✓ | ✗ |
| Fork | ✓ | ✗ | ✓ | ✗ |
| Delete | ✓ | ✓ | ✓ | ✓ |
| Spot (Preemption) | ✓ | ✓ | ✗ | ✗ |
States
A state is the condition of a sandbox at one point in its lifecycle, such as starting, running, or stopped. The state decides which requests the sandbox accepts and which actions can move it to another state.
A state is reported for every sandbox, and some interfaces use a status name instead of the state name. A sandbox moves to another state when an action, a timeout, or the platform changes it, and each move has one trigger.
Read the state of a sandbox before you act on it, and wait for a state when the next step needs one. The states table pairs each state with its status name, and the transitions table lists each move with its trigger.
| State | API status | Description |
|---|---|---|
queued | queued | The create request is recorded and waits for its image before it is published for placement. |
creating | pending, assigned | The sandbox waits for a host, and the host it is placed on prepares its image. |
starting | booting | The virtual machine is booting and will be ready to use. |
started | running | The sandbox is running and ready to accept requests. |
pausing | pausing | The sandbox is saving its memory and processes before it pauses. |
paused | paused | The memory, processes, and disk of a persistent sandbox are saved, and it accepts no requests. |
stopping | stopping | The virtual machine is shutting down. |
stopped | stopped | The virtual machine of a persistent sandbox is shut down, its disk is kept, and it accepts no requests. |
destroying | deleting | The sandbox is being deleted. |
destroyed | deleted | The sandbox and its storage are removed. |
error | failed, lost | The image build, create, or boot failed, or the host or virtual machine of the sandbox was lost. |
unknown | The SDK does not recognize the status the API reports. |
| Initial state | Target state | Trigger |
|---|---|---|
queued | creating | The image is ready and the create request is published for placement. |
creating | starting | The host has prepared the image and boots the virtual machine. |
starting | started | The sandbox finishes booting and accepts requests. |
started | stopping | A stop or a restart is requested, or a timeout with the stop action elapses. |
stopping | stopped | The virtual machine has shut down and the disk is kept. |
started | pausing | A pause is requested, or a timeout with the pause action elapses. |
pausing | paused | The memory and processes are saved. |
stopped, paused | creating | A start or a resume is requested. |
creating, starting, started | destroying | A delete is requested, a timeout elapses, or the platform reclaims a spot sandbox. |
queued, creating, stopped, paused, error | destroyed | A delete is requested for a sandbox with no running virtual machine, so it skips destroying. |
started | destroyed | The virtual machine shuts down on its own. |
destroying | destroyed | The sandbox is removed and its resources are released. |
queued, creating, starting | error | The image build, create, or boot fails. |
creating, starting, started, destroying | error | The host of the sandbox is lost. |
Wait for state
Wait for a sandbox to reach a state before a step that needs that state. A wait is a call that blocks until a resource reaches a target state or a time limit passes, without polling.
A wait on a sandbox returns as soon as the sandbox reaches one of the target states. It stops early in a state from which the target is unreachable, such as the error or destroyed state.
Wait for the sandbox to start after a create that returns at once, so that the next step finds it running. The sandbox states table pairs each state with the status name that some interfaces use instead.
from daytona import Daytona
daytona = Daytona()
# Return from create without waiting for the sandbox to start
sandbox = daytona.v2.create(wait_seconds=0)
# Block until the sandbox is started; returns the sandbox
sandbox.wait(until="started", timeout=60)
# Block until the sandbox is in one of the listed states
sandbox.wait(until=["starting", "started"], timeout=60)| Parameter | Description |
|---|---|
timeout | Sets the wait limit in seconds. Default: 60Value: 0 for no limitExample: 120 |
until | Sets one state or a list of states, and wait() returns on any of them. Default: "started"Value: queued, starting, started, pausing, paused, stopping, stopped, destroying, or destroyedExample: "stopped" |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
// Return from create without waiting for the sandbox to start
const sandbox = await daytona.v2.create({ waitSeconds: 0 })
// Block until the sandbox is started; returns the sandbox
await sandbox.wait({ until: 'started', timeoutSeconds: 60 })
// Block until the sandbox is in one of the listed states
await sandbox.wait({ until: ['starting', 'started'], timeoutSeconds: 60 })| Parameter | Description |
|---|---|
timeoutSeconds | Sets the wait limit in seconds. Default: 60Value: 0 for no limitExample: 120 |
until | Sets one state or a list of states, and wait() returns on any of them. Default: 'started'Value: queued, starting, started, pausing, paused, stopping, stopped, destroying, or destroyedExample: 'stopped' |
package main
import (
"context"
"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()
// Return from Create without waiting for the sandbox to start
sandbox, err := client.Create(ctx, "", &daytona.CreateOptions{Wait: daytona.NoWait})
if err != nil {
log.Fatal(err)
}
// Block until the sandbox is started
err = sandbox.Wait(ctx, &daytona.WaitOptions{
Until: []daytona.SandboxState{daytona.SandboxStateStarted},
Timeout: time.Minute,
})
if err != nil {
log.Fatal(err)
}
// Block until the sandbox is in one of the listed states
err = sandbox.Wait(ctx, &daytona.WaitOptions{
Until: []daytona.SandboxState{daytona.SandboxStateStarting, daytona.SandboxStateStarted},
Timeout: time.Minute,
})
if err != nil {
log.Fatal(err)
}
}| Parameter | Description |
|---|---|
Timeout | Sets the wait limit. Default: time.MinuteValue: daytona.NoWait to skip the wait, daytona.WaitForever for no limitExample: 2*time.Minute |
Until | Sets the states, and Wait returns on any of them. Default: []daytona.SandboxState{daytona.SandboxStateStarted}Format: a non-empty list Value: daytona.SandboxStateQueued, daytona.SandboxStateStarting, daytona.SandboxStateStarted, daytona.SandboxStatePausing, daytona.SandboxStatePaused, daytona.SandboxStateStopping, daytona.SandboxStateStopped, daytona.SandboxStateDestroying, or daytona.SandboxStateDestroyedExample: []daytona.SandboxState{daytona.SandboxStateStopped} |
# Block until the sandbox is running, or the timeout elapses
daytona sandbox wait {sandboxId} --for running --timeout 60s| Flag | Description |
|---|---|
--for | Sets the state to wait for. Default: runningValue: running, stopped, paused, or deleted, or the SDK names started and destroyedExample: stopped |
--timeout | Sets how long the command waits. Default: 10mFormat: a Go duration greater than zero Example: 5m |
# Long-poll until the sandbox is running, a terminal state, or the timeout elapses
curl 'https://api.daytona.com/sandboxes/{sandboxId}?wait=running&timeout_ms=60000' \
--header 'Authorization: Bearer YOUR_API_KEY'
# Long-poll until the sandbox is exactly deleted; wait_exact skips the transient deleting state
curl 'https://api.daytona.com/sandboxes/{sandboxId}?wait_exact=deleted&timeout_ms=60000' \
--header 'Authorization: Bearer YOUR_API_KEY'| Field | Description |
|---|---|
timeout_ms | Sets the wait limit in milliseconds. Default: 30000Minimum: 0Maximum: 60000 |
wait | Blocks the response until the sandbox reaches this status. Value: an API status in the sandbox states, such as runningExample: running |
wait_exact | Blocks the response until the sandbox reaches exactly this status. Value: an API status in the sandbox states Example: deleted |
Stop / start
Stop a sandbox to shut down its operating system and free its processor and memory, and start it to boot again from the same disk. A stop is a clean shutdown that keeps the disk, unlike a delete.
A stop of a persistent sandbox ends its processes and keeps its disk, and a start boots it again from that disk. A stopped sandbox accepts no requests, and a request to it does not start it.
Stop a persistent sandbox between sessions to free its processor and memory, and start it when the work continues. Each call returns once the sandbox reaches the new state.
| Sandbox type | Restart | Disk | Start | Reservation |
|---|---|---|---|---|
| Linux | ✓ | Kept | Boots from the kept disk | None |
| Windows | ✓ | Kept | Boots from the kept disk | None |
| macOS | ✗ | Kept on the same Mac, which keeps its disk room, while its cores, memory, and slot become available to other sandboxes | Boots on any Mac of the organization that has room, and iCloud asks the user to sign in again after a move to a different Mac | A start with no reservation in the region buys one if auto-reserve is on. A stopped sandbox does not keep automatic renewal going |
- Go to Daytona Sandboxes ↗
- Click the sandbox
- Click Stop
- Click Start
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create(persistent=True)
sandbox.stop()
sandbox.start(timeout=120)
# Restart a running Linux or Windows sandbox in one call
sandbox.restart(timeout=120)
# Stop a sandbox by ID, without fetching it first
daytona.v2.stop("SANDBOX_ID")
# Start a stopped sandbox by ID
daytona.v2.start("SANDBOX_ID", timeout=120)
# Restart a running Linux or Windows sandbox by ID
daytona.v2.restart("SANDBOX_ID", timeout=120)| Parameter | Description |
|---|---|
timeout | Sets how many seconds the call waits for the sandbox to reach the new state. Default: 60Value: 0 for no limitExample: 120 |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create({ persistent: true })
await sandbox.stop()
await sandbox.start({ timeoutSeconds: 120 })
// Restart a running Linux or Windows sandbox in one call
await sandbox.restart({ timeoutSeconds: 120 })
// Stop a sandbox by ID, without fetching it first
await daytona.v2.stop('SANDBOX_ID')
// Start a stopped sandbox by ID
await daytona.v2.start('SANDBOX_ID', { timeoutSeconds: 120 })
// Restart a running Linux or Windows sandbox by ID
await daytona.v2.restart('SANDBOX_ID', { timeoutSeconds: 120 })| Parameter | Description |
|---|---|
timeoutSeconds | Sets how many seconds the call waits for the sandbox to reach the new state. Default: 60Value: 0 for no limitExample: 120 |
package main
import (
"context"
"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()
persistent := true
sandbox, err := client.Create(ctx, "", &daytona.CreateOptions{Persistent: &persistent})
if err != nil {
log.Fatal(err)
}
if err = sandbox.Stop(ctx, nil); err != nil {
log.Fatal(err)
}
if err = sandbox.Start(ctx, &daytona.LifecycleWaitOptions{Timeout: 120 * time.Second}); err != nil {
log.Fatal(err)
}
// Restart a running Linux or Windows sandbox in one call
if err = sandbox.Restart(ctx, &daytona.LifecycleWaitOptions{Timeout: 120 * time.Second}); err != nil {
log.Fatal(err)
}
// Stop a sandbox by ID, without fetching it first
if err = client.Stop(ctx, "SANDBOX_ID", nil); err != nil {
log.Fatal(err)
}
// Start a stopped sandbox by ID
if err = client.Start(ctx, "SANDBOX_ID", &daytona.LifecycleWaitOptions{Timeout: 120 * time.Second}); err != nil {
log.Fatal(err)
}
// Restart a running Linux or Windows sandbox by ID
if err = client.Restart(ctx, "SANDBOX_ID", &daytona.LifecycleWaitOptions{Timeout: 120 * time.Second}); err != nil {
log.Fatal(err)
}
}| Parameter | Description |
|---|---|
Timeout | Sets how long the call waits for the sandbox to reach the new state. Default: 60*time.SecondValue: daytona.NoWait for no wait, daytona.WaitForever for no limitExample: 120*time.Second |
daytona sandbox stop SANDBOX_ID
daytona sandbox start SANDBOX_ID
# Restart a running Linux or Windows sandbox in one command
daytona sandbox restart SANDBOX_IDcurl 'https://api.daytona.com/sandboxes/{sandboxId}/stop' \
--request POST \
--header 'Authorization: Bearer YOUR_API_KEY'
# Long-poll until the sandbox is stopped
curl 'https://api.daytona.com/sandboxes/{sandboxId}?wait=stopped&timeout_ms=60000' \
--header 'Authorization: Bearer YOUR_API_KEY'
curl 'https://api.daytona.com/sandboxes/{sandboxId}/start' \
--request POST \
--header 'Authorization: Bearer YOUR_API_KEY'
# Restart a running Linux or Windows sandbox in one request
curl 'https://api.daytona.com/sandboxes/{sandboxId}/restart' \
--request POST \
--header 'Authorization: Bearer YOUR_API_KEY'| Field | Description |
|---|---|
timeout_ms | Sets the wait limit in milliseconds. Default: 30000Minimum: 0Maximum: 60000 |
wait | Blocks the response until the sandbox reaches this status. Value: an API status, such as stoppedExample: stopped |
Pause / resume
Pause a sandbox to freeze its processes and save its memory, and resume it to continue where it stopped. A pause keeps running work without the cost of a new boot.
A pause of a persistent sandbox saves its memory, processes, and disk, and a resume continues them without a new boot. A paused sandbox accepts no requests, and a request to it does not resume it.
Pause a persistent sandbox to keep its processes between sessions without holding its processor and memory. A sandbox that cannot pause can still stop, which keeps its disk.
| Sandbox type | Volumes | Resume | Reservation |
|---|---|---|---|
| Linux | A sandbox with volumes attached cannot pause | Continues the processes with the same boot | None |
| macOS | Not supported | Continues from the saved memory, or boots from the disk when the memory cannot be restored, and then reports mac_boot_mode cold_after_restore_failure | A paused sandbox keeps its place on the reservation and counts as active, so its reservation keeps renewing |
- Go to Daytona Sandboxes ↗
- Click the sandbox
- Click Pause
- Click Resume
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create(persistent=True)
sandbox.pause()
sandbox.resume()
# Pause a sandbox by ID, without fetching it first
daytona.v2.pause("SANDBOX_ID")
# Resume a paused sandbox by ID
daytona.v2.resume("SANDBOX_ID")| Parameter | Description |
|---|---|
timeout | Sets how many seconds the call waits for the sandbox to reach the new state. Default: 60Value: 0 for no limitExample: 120 |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create({ persistent: true })
await sandbox.pause()
await sandbox.resume()
// Pause a sandbox by ID, without fetching it first
await daytona.v2.pause('SANDBOX_ID')
// Resume a paused sandbox by ID
await daytona.v2.resume('SANDBOX_ID')| Parameter | Description |
|---|---|
timeoutSeconds | Sets how many seconds the call waits for the sandbox to reach the new state. Default: 60Value: 0 for no limitExample: 120 |
package main
import (
"context"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
persistent := true
sandbox, err := client.Create(ctx, "", &daytona.CreateOptions{Persistent: &persistent})
if err != nil {
log.Fatal(err)
}
if err = sandbox.Pause(ctx, nil); err != nil {
log.Fatal(err)
}
if err = sandbox.Resume(ctx, nil); err != nil {
log.Fatal(err)
}
// Pause a sandbox by ID, without fetching it first
if err = client.Pause(ctx, "SANDBOX_ID", nil); err != nil {
log.Fatal(err)
}
// Resume a paused sandbox by ID
if err = client.Resume(ctx, "SANDBOX_ID", nil); err != nil {
log.Fatal(err)
}
}| Parameter | Description |
|---|---|
Timeout | Sets how long the call waits for the sandbox to reach the new state. Default: 60*time.SecondValue: daytona.NoWait for no wait, daytona.WaitForever for no limitExample: 120*time.Second |
daytona sandbox pause SANDBOX_ID
daytona sandbox resume SANDBOX_IDcurl 'https://api.daytona.com/sandboxes/{sandboxId}/pause' \
--request POST \
--header 'Authorization: Bearer YOUR_API_KEY'
curl 'https://api.daytona.com/sandboxes/{sandboxId}/resume' \
--request POST \
--header 'Authorization: Bearer YOUR_API_KEY'Fork
Fork a sandbox to copy its disk into a new, independent sandbox. A fork branches the state of a machine so that two copies continue separately.
A fork of a persistent sandbox is a new sandbox with its own ID, made from a copy of the disk of the source. The source keeps its state, and the fork continues separately from it.
Fork a sandbox to try several changes from one state without touching the source. Give each fork its own name to tell the copies apart.
| Sandbox type | Memory | Running source | Paused or stopped source |
|---|---|---|---|
| Linux | Copied by default, which pauses the source briefly | The fork starts on its own and continues the processes of the source, or boots fresh without memory | The fork stays paused with memory, or stopped without, until it is resumed or started |
| macOS | Never copied, and a request for memory fails | The fork boots with a new machine identity | The fork starts with a copy of the disk |
- Go to Daytona Sandboxes ↗
- Click the sandbox
- Click Fork
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create(persistent=True)
fork = sandbox.fork(name="agent-workspace-2")| Parameter | Description |
|---|---|
memory | Copies the memory and running processes of the source into the fork. Default: True on a Linux sandboxRules: not True on a macOS sandbox, which forks its disk only |
name | Sets the display name of the fork. Default: the source name followed by -fork, or a generated name when that is not a valid name Format: 1 to 128 letters, digits, periods, underscores, and hyphens, not starting with a period or a reserved prefix: sbx_, vol_, fn_, img_, snap_, snap-, build-, refs, by-digest, prj-, or glb- Example: "agent-workspace-2" |
wait_seconds | Sets how many seconds the call waits for the fork to settle. Default: 60Value: 0 for no waitExample: 120 |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create({ persistent: true })
const fork = await sandbox.fork({ name: 'agent-workspace-2' })| Parameter | Description |
|---|---|
memory | Copies the memory and running processes of the source into the fork. Default: true on a Linux sandboxRules: not true on a macOS sandbox, which forks its disk only |
name | Sets the display name of the fork. Default: the source name followed by -fork, or a generated name when that is not a valid name Format: 1 to 128 letters, digits, periods, underscores, and hyphens, not starting with a period or a reserved prefix: sbx_, vol_, fn_, img_, snap_, snap-, build-, refs, by-digest, prj-, or glb- Example: 'agent-workspace-2' |
waitSeconds | Sets how many seconds the call waits for the fork to settle. Default: 60Value: 0 for no waitExample: 120 |
package main
import (
"context"
"log"
"go.daytona.com/sdk/v2"
)
func main() {
ctx := context.Background()
client, err := daytona.New()
if err != nil {
log.Fatal(err)
}
defer client.Close()
persistent := true
sandbox, err := client.Create(ctx, "", &daytona.CreateOptions{Persistent: &persistent})
if err != nil {
log.Fatal(err)
}
_, err = sandbox.Fork(ctx, &daytona.ForkOptions{Name: "agent-workspace-2"})
if err != nil {
log.Fatal(err)
}
}| Parameter | Description |
|---|---|
Memory | Copies the memory and running processes of the source into the fork. Default: true on a Linux sandboxFormat: a pointer to a bool Rules: not true on a macOS sandbox, which forks its disk only |
Name | Sets the display name of the fork. Default: the source name followed by -fork, or a generated name when that is not a valid name Format: 1 to 128 letters, digits, periods, underscores, and hyphens, not starting with a period or a reserved prefix: sbx_, vol_, fn_, img_, snap_, snap-, build-, refs, by-digest, prj-, or glb- Example: "agent-workspace-2" |
Wait | Sets how long the call waits for the fork to settle. Default: 60*time.SecondValue: daytona.NoWait for no wait, daytona.WaitForever for no limitExample: 120*time.Second |
daytona sandbox fork SANDBOX_ID --name agent-workspace-2| Flag | Description |
|---|---|
--memory | Copies the memory and running processes of the source into the fork. Default: true on a Linux sandboxRules: not true on a macOS sandbox, which forks its disk only |
--name | Sets the display name of the fork. Default: the source name followed by -fork, or a generated name when that is not a valid name Format: 1 to 128 letters, digits, periods, underscores, and hyphens, not starting with a period or a reserved prefix: sbx_, vol_, fn_, img_, snap_, snap-, build-, refs, by-digest, prj-, or glb- Example: agent-workspace-2 |
curl 'https://api.daytona.com/sandboxes/{sandboxId}/fork' \
--request POST \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{ "name": "agent-workspace-2" }'| Field | Description |
|---|---|
memory | Copies the memory and running processes of the source into the fork. Default: true on a Linux sandboxRules: not true on a macOS sandbox, which forks its disk only |
name | Sets the display name of the fork. Default: the source name followed by -fork, or a generated name when that is not a valid name Format: 1 to 128 letters, digits, periods, underscores, and hyphens, not starting with a period or a reserved prefix: sbx_, vol_, fn_, img_, snap_, snap-, build-, refs, by-digest, prj-, or glb- Example: "agent-workspace-2" |
Timeouts
Timeouts are timers that end a sandbox automatically after a set interval. They keep a sandbox that fails to start, outlives its work, or goes unused from holding resources.
A sandbox has three timeouts: the create timeout deletes a sandbox that does not start in time, and the lifetime and idle timeouts act on a running one. When one of these elapses, an ephemeral sandbox is deleted, and a persistent one takes the action that the timeout sets.
Set a create timeout to delete a sandbox that does not start in time, and a lifetime timeout to cap how long it runs. Set an idle timeout with its action to act on a sandbox once unused, and reset the idle timer during background work. Change the timeouts later with an update.
| Timeout | Default | Action |
|---|---|---|
| Create | 3600 seconds | Delete |
| Lifetime | The project's lifecycle default, otherwise 300 seconds, lowered to the organization's maximum | Delete on an ephemeral sandbox, and an action of its type on a persistent one, with the default of its type |
| Idle | None, unless the project sets one | Delete on an ephemeral sandbox, and an action of its type on a persistent one, with no default |
| Sandbox type | Delete | Stop | Pause | Default for a persistent sandbox |
|---|---|---|---|---|
| Linux | ✓ | Persistent | Persistent | Pause |
| Windows | ✓ | Persistent | ✗ | Stop |
| macOS | ✓ | Persistent | ✗ | Stop |
| GPU | ✓ | ✗ | ✗ | None, because a GPU sandbox is always ephemeral |
| Activity | Idle timeout | Lifetime timeout |
|---|---|---|
| Request or connection | Restarts the countdown while it is open | No effect |
| Command | Restarts the countdown while a request for it, such as a wait, is open | No effect |
| Background command | No effect once the request that started it returns | No effect |
| Idle timer reset | Restarts the countdown | No effect |
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create(
create_timeout_seconds=600,
lifecycle_policy={
"timeout_seconds": 86400,
"on_timeout": "delete",
"idle_expiry_seconds": 3600,
"on_idle_timeout": "delete",
},
)| Parameter | Description |
|---|---|
create_timeout_seconds | Sets how many seconds the sandbox has to reach running before it is deleted. Default: 3600Minimum: 1Maximum: 86400Value: -1 for the maximumExample: 600 |
lifecycle_policy | Sets the timeouts of the sandbox. Example: {"timeout_seconds": 3600, "on_timeout": "delete"} |
timeout_seconds | Sets the wall-clock lifetime of the sandbox in seconds. Default: the project's lifecycle default, otherwise 300, lowered to the organization's maximumMinimum: 1Maximum: 86400, unless the organization or its plan sets a different maximum |
on_timeout | Sets the action when the timeout elapses. Default: the project's lifecycle default when timeout_seconds is not set, otherwise "delete", or "pause" for a persistent Linux sandbox and "stop" for a persistent Windows or macOS sandboxValue: "delete", or "stop" for a persistent sandbox, and "pause" for a persistent Linux sandbox |
idle_expiry_seconds | Sets the seconds without activity before the idle action fires. Default: none, unless the project sets one Minimum: 60Maximum: 2147483647Rules: only with on_idle_timeout Value: DISABLED for no idle timeout |
on_idle_timeout | Sets the action when the idle timeout elapses. Rules: only with idle_expiry_seconds Value: "delete", or "stop" for a persistent sandbox, and "pause" for a persistent Linux sandbox |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create({
createTimeoutSeconds: 600,
lifecyclePolicy: {
timeoutSeconds: 86400,
onTimeout: 'delete',
idleExpirySeconds: 3600,
onIdleTimeout: 'delete',
},
})| Parameter | Description |
|---|---|
createTimeoutSeconds | Sets how many seconds the sandbox has to reach running before it is deleted. Default: 3600Minimum: 1Maximum: 86400Value: -1 for the maximumExample: 600 |
lifecyclePolicy | Sets the timeouts of the sandbox. Example: { timeoutSeconds: 3600, onTimeout: 'delete' } |
timeoutSeconds | Sets the wall-clock lifetime of the sandbox in seconds. Default: the project's lifecycle default, otherwise 300, lowered to the organization's maximumMinimum: 1Maximum: 86400, unless the organization or its plan sets a different maximum |
onTimeout | Sets the action when the timeout elapses. Default: the project's lifecycle default when timeoutSeconds is not set, otherwise 'delete', or 'pause' for a persistent Linux sandbox and 'stop' for a persistent Windows or macOS sandboxValue: 'delete', or 'stop' for a persistent sandbox, and 'pause' for a persistent Linux sandbox |
idleExpirySeconds | Sets the seconds without activity before the idle action fires. Default: none, unless the project sets one Minimum: 60Maximum: 2147483647Rules: only with onIdleTimeout Value: DISABLED for no idle timeout |
onIdleTimeout | Sets the action when the idle timeout elapses. Rules: only with idleExpirySeconds Value: 'delete', or 'stop' for a persistent sandbox, and 'pause' for a persistent Linux sandbox |
package main
import (
"context"
"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()
createTimeout := 10 * time.Minute
_, err = client.Create(ctx, "", &daytona.CreateOptions{
CreateTimeout: &createTimeout,
LifecyclePolicy: &daytona.LifecyclePolicyOptions{
Timeout: 24 * time.Hour,
OnTimeout: daytona.LifecycleActionDelete,
IdleExpiry: time.Hour,
OnIdleTimeout: daytona.LifecycleActionDelete,
},
})
if err != nil {
log.Fatal(err)
}
}| Parameter | Description |
|---|---|
CreateTimeout | Sets how long the sandbox has to reach running before it is deleted. Default: time.HourMinimum: time.SecondMaximum: 24*time.HourFormat: a pointer to a whole number of seconds Value: daytona.WaitForever for the maximum |
LifecyclePolicy | Sets the timeouts of the sandbox. Example: &daytona.LifecyclePolicyOptions{Timeout: time.Hour, OnTimeout: daytona.LifecycleActionDelete} |
Timeout | Sets the wall-clock lifetime of the sandbox. Default: the project's lifecycle default, otherwise 5*time.Minute, lowered to the organization's maximumMinimum: time.SecondMaximum: 24*time.Hour, unless the organization or its plan sets a different maximumFormat: a whole number of seconds |
OnTimeout | Sets the action when the timeout elapses. Default: the project's lifecycle default when Timeout is not set, otherwise daytona.LifecycleActionDelete, or daytona.LifecycleActionPause for a persistent Linux sandbox and daytona.LifecycleActionStop for a persistent Windows or macOS sandboxValue: daytona.LifecycleActionDelete, or daytona.LifecycleActionStop for a persistent sandbox, and daytona.LifecycleActionPause for a persistent Linux sandbox |
IdleExpiry | Sets the time without activity before the idle action fires. Default: none, unless the project sets one Minimum: time.MinuteMaximum: 2147483647*time.SecondFormat: a whole number of seconds Rules: only with OnIdleTimeout Value: daytona.NoTimeout for no idle timeout |
OnIdleTimeout | Sets the action when the idle timeout elapses. Rules: only with IdleExpiry Value: daytona.LifecycleActionDelete, or daytona.LifecycleActionStop for a persistent sandbox, and daytona.LifecycleActionPause for a persistent Linux sandbox |
daytona sandbox create \
--create-ttl 10m \
--lifecycle-timeout 24h --on-lifecycle-timeout delete \
--idle-timeout 1h --on-idle-timeout delete| Flag | Description |
|---|---|
--create-ttl | Sets how long the sandbox has to reach running before the server deletes it. Default: 1hMinimum: 1sMaximum: 24hFormat: a Go duration Value: max for the maximumExample: 10m |
--idle-timeout | Sets the time without activity until --on-idle-timeout fires. Default: none, unless the project sets one Minimum: 1mMaximum: 2147483647sFormat: a Go duration Rules: only with --on-idle-timeout |
--lifecycle-timeout | Sets the wall-clock lifetime of the sandbox. Default: the project's lifecycle default, otherwise 5m, lowered to the organization's maximumMinimum: 1sMaximum: 24h, unless the organization or its plan sets a different maximumFormat: a Go duration Example: 2h |
--on-idle-timeout | Sets the action when --idle-timeout elapses. Rules: only with --idle-timeout, unless the project sets an idle timeout Value: delete, or stop for a persistent sandbox, and pause for a persistent Linux sandbox |
--on-lifecycle-timeout | Sets the action when --lifecycle-timeout elapses. Default: the project's lifecycle default when --lifecycle-timeout is not set, otherwise delete, or pause for a persistent Linux sandbox and stop for a persistent Windows or macOS sandboxValue: delete, or stop for a persistent sandbox, and pause for a persistent Linux sandbox |
curl 'https://api.daytona.com/sandboxes' \
--request POST \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{
"create_timeout_seconds": 600,
"lifecycle_policy": {
"timeout_seconds": 86400,
"on_timeout": "delete",
"idle_expiry_seconds": 3600,
"on_idle_timeout": "delete"
}
}'| Field | Description |
|---|---|
create_timeout_seconds | Sets how many seconds the sandbox has to reach running before it is deleted. Default: 3600Minimum: 1Maximum: 86400Value: -1 for the maximumExample: 600 |
lifecycle_policy | Sets the timeouts of the sandbox. Example: {"timeout_seconds": 3600, "on_timeout": "delete"} |
timeout_seconds | Sets the wall-clock lifetime of the sandbox in seconds. Default: the project's lifecycle default, otherwise 300, lowered to the organization's maximumMinimum: 1Maximum: 86400, unless the organization or its plan sets a different maximum |
on_timeout | Sets the action when the timeout elapses. Default: the project's lifecycle default when timeout_seconds is not set, otherwise delete, or pause for a persistent Linux sandbox and stop for a persistent Windows or macOS sandboxValue: delete, or stop for a persistent sandbox, and pause for a persistent Linux sandbox |
idle_expiry_seconds | Sets the seconds without activity before the idle action fires. Default: none, unless the project sets one Minimum: 60Maximum: 2147483647Rules: only with on_idle_timeout Value: -1 for no idle timeout |
on_idle_timeout | Sets the action when the idle timeout elapses. Rules: only with idle_expiry_seconds, unless the project sets an idle timeout Value: delete, or stop for a persistent sandbox, and pause for a persistent Linux sandbox |
Reset the idle timer
Reset the idle timer to count a sandbox as active without sending it a request. An idle timer measures the time since the last activity and fires its action when that time reaches the idle timeout.
A reset of the idle timer of a sandbox counts as activity, so the idle timeout counts again from the reset. The lifetime timeout keeps its deadline. A reset works in every state except deleting and deleted, and a sandbox without an idle timeout returns no idle deadline.
Reset the idle timer during work that does not count as activity, such as a background command or a job outside the sandbox. To change the length of the idle timeout instead, update the sandbox. A reset needs a project API key, so code inside the sandbox cannot keep its own sandbox running with a sandbox token.
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create(lifecycle_policy={"idle_expiry_seconds": 3600, "on_idle_timeout": "delete"})
lifecycle = sandbox.reset_idle_timer()
print(lifecycle.last_activity_at, lifecycle.idle_timeout_at)import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create({ lifecyclePolicy: { idleExpirySeconds: 3600, onIdleTimeout: 'delete' } })
const lifecycle = await sandbox.resetIdleTimer()
console.log(lifecycle.lastActivityAt, lifecycle.idleTimeoutAt)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, "", &daytona.CreateOptions{
LifecyclePolicy: &daytona.LifecyclePolicyOptions{IdleExpiry: time.Hour, OnIdleTimeout: daytona.LifecycleActionDelete},
})
if err != nil {
log.Fatal(err)
}
lifecycle, err := sandbox.ResetIdleTimer(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(lifecycle.LastActivityAt, lifecycle.IdleTimeoutAt)
}curl 'https://api.daytona.com/sandboxes/{sandboxId}/reset-idle-timer' \
--request POST \
--header 'Authorization: Bearer YOUR_API_KEY'Update
Update a sandbox to change its timeouts after it is created. An update is a partial change to an existing resource: it sets the fields it names and keeps the rest.
An update of a sandbox changes its lifetime and idle timeouts in place, without recreating the sandbox. A new lifetime timeout counts from the update, not from the start of the sandbox.
Update a sandbox to move its lifetime timeout, or to set or clear its idle timeout. An ephemeral sandbox takes only the delete action, and updating a deleting or deleted sandbox fails.
| Sandbox type | Actions | Wake on request |
|---|---|---|
| Linux | Delete, and stop and pause on a persistent sandbox | Persistent |
| Windows | Delete, and stop on a persistent sandbox | ✗ |
| macOS | Delete, and stop on a persistent sandbox | ✗ |
from daytona import Daytona
from daytona.v2 import DISABLED
daytona = Daytona()
sandbox = daytona.v2.create()
# Delete the sandbox after 30 minutes without activity; omitted fields keep their current value
lifecycle = sandbox.update_lifecycle_policy(idle_expiry_seconds=1800, on_idle_timeout="delete")
print(lifecycle.idle_expiry_seconds, lifecycle.on_idle_timeout)
# Re-anchor the timeout to 1 hour from now
lifecycle = sandbox.update_lifecycle_policy(timeout_seconds=3600)
print(lifecycle.timeout_at)
# Clear the idle timeout
lifecycle = sandbox.update_lifecycle_policy(idle_expiry_seconds=DISABLED)| Parameter | Description |
|---|---|
idle_expiry_seconds | Sets the seconds without activity before the idle action. Minimum: 60Maximum: 2147483647Value: DISABLED for no idle timeoutExample: 1800 |
on_idle_timeout | Sets the idle action. Value: "delete", or "stop" for a persistent sandbox, and "pause" for a persistent Linux sandbox |
on_timeout | Sets the timeout action. Value: "delete", or "stop" for a persistent sandbox, and "pause" for a persistent Linux sandbox |
timeout_seconds | Sets the seconds until the timeout, counted from now. Minimum: 1Maximum: 86400, unless the organization or its plan sets a different maximumExample: 3600 |
wake_on_request | Starts or resumes the sandbox when an authenticated toolbox, SSH, or private-preview request arrives. Rules: True only for a persistent Linux sandbox |
import { Daytona } from '@daytona/sdk'
import { DISABLED } from '@daytona/sdk/v2'
const daytona = new Daytona()
const sandbox = await daytona.v2.create()
// Delete the sandbox after 30 minutes without activity; omitted fields keep their current value
let lifecycle = await sandbox.updateLifecyclePolicy({ idleExpirySeconds: 1800, onIdleTimeout: 'delete' })
console.log(lifecycle.idleExpirySeconds, lifecycle.onIdleTimeout)
// Re-anchor the timeout to 1 hour from now
lifecycle = await sandbox.updateLifecyclePolicy({ timeoutSeconds: 3600 })
console.log(lifecycle.timeoutAt)
// Clear the idle timeout
lifecycle = await sandbox.updateLifecyclePolicy({ idleExpirySeconds: DISABLED })| Parameter | Description |
|---|---|
idleExpirySeconds | Sets the seconds without activity before the idle action. Minimum: 60Maximum: 2147483647Value: DISABLED for no idle timeoutExample: 1800 |
onIdleTimeout | Sets the idle action. Value: 'delete', or 'stop' for a persistent sandbox, and 'pause' for a persistent Linux sandbox |
onTimeout | Sets the timeout action. Value: 'delete', or 'stop' for a persistent sandbox, and 'pause' for a persistent Linux sandbox |
timeoutSeconds | Sets the seconds until the timeout, counted from now. Minimum: 1Maximum: 86400, unless the organization or its plan sets a different maximumExample: 3600 |
wakeOnRequest | Starts or resumes the sandbox when an authenticated toolbox, SSH, or private-preview request arrives. Rules: true only for a persistent Linux sandbox |
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)
}
// Delete the sandbox after 30 minutes without activity; omitted fields keep their current value
lifecycle, err := sandbox.UpdateLifecyclePolicy(ctx, &daytona.LifecyclePolicyOptions{
IdleExpiry: 30 * time.Minute,
OnIdleTimeout: daytona.LifecycleActionDelete,
})
if err != nil {
log.Fatal(err)
}
if lifecycle.IdleExpiry != nil {
fmt.Println(*lifecycle.IdleExpiry, lifecycle.OnIdleTimeout)
}
// Re-anchor the timeout to 1 hour from now
lifecycle, err = sandbox.UpdateLifecyclePolicy(ctx, &daytona.LifecyclePolicyOptions{Timeout: time.Hour})
if err != nil {
log.Fatal(err)
}
fmt.Println(lifecycle.TimeoutAt)
// Clear the idle timeout
_, err = sandbox.UpdateLifecyclePolicy(ctx, &daytona.LifecyclePolicyOptions{IdleExpiry: daytona.NoTimeout})
if err != nil {
log.Fatal(err)
}
}| Parameter | Description |
|---|---|
IdleExpiry | Sets the time without activity before the idle action. Minimum: time.MinuteMaximum: 2147483647*time.SecondFormat: a whole number of seconds Rules: daytona.NoTimeout not with OnIdleTimeoutValue: daytona.NoTimeout for no idle timeoutExample: 30*time.Minute |
OnIdleTimeout | Sets the idle action. Rules: not with IdleExpiry daytona.NoTimeoutValue: daytona.LifecycleActionDelete, or daytona.LifecycleActionStop for a persistent sandbox, and daytona.LifecycleActionPause for a persistent Linux sandbox |
OnTimeout | Sets the timeout action. Value: daytona.LifecycleActionDelete, or daytona.LifecycleActionStop for a persistent sandbox, and daytona.LifecycleActionPause for a persistent Linux sandbox |
Timeout | Sets the time until the timeout, counted from now. Minimum: time.SecondMaximum: 24*time.Hour, unless the organization or its plan sets a different maximumFormat: a whole number of seconds Example: time.Hour |
WakeOnRequest | Starts or resumes the sandbox when an authenticated toolbox, SSH, or private-preview request arrives. Format: a pointer to a bool Rules: true only for a persistent Linux sandbox |
# Delete the sandbox after 30 minutes without activity
daytona sandbox update {sandboxId} --idle-timeout 30m --on-idle-timeout delete
# Re-anchor the timeout to 1 hour from now
daytona sandbox update {sandboxId} --lifecycle-timeout 1h
# Clear the idle timeout
daytona sandbox update {sandboxId} --idle-timeout off| Flag | Description |
|---|---|
--idle-timeout | Sets the time without activity before the idle action. Minimum: 1mMaximum: 2147483647sFormat: a Go duration Value: off for no idle timeoutExample: 30m |
--lifecycle-timeout | Sets the time until the timeout, counted from now. Minimum: 1sMaximum: 24h, unless the organization or its plan sets a different maximumFormat: a Go duration Example: 1h |
--on-idle-timeout | Sets the idle action. Value: delete, or stop for a persistent sandbox, and pause for a persistent Linux sandbox |
--on-lifecycle-timeout | Sets the timeout action. Value: delete, or stop for a persistent sandbox, and pause for a persistent Linux sandbox |
--wake-on-request | Starts or resumes the sandbox when an authenticated toolbox, SSH, or private-preview request arrives. Rules: true only for a persistent Linux sandbox |
# Delete the sandbox after 30 minutes without activity
curl 'https://api.daytona.com/sandboxes/{sandboxId}/lifecycle-policy' \
--request PATCH \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{ "idle_expiry_seconds": 1800, "on_idle_timeout": "delete" }'
# Re-anchor the timeout to 1 hour from now
curl 'https://api.daytona.com/sandboxes/{sandboxId}/lifecycle-policy' \
--request PATCH \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{ "timeout_seconds": 3600 }'
# Clear the idle timeout
curl 'https://api.daytona.com/sandboxes/{sandboxId}/lifecycle-policy' \
--request PATCH \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{ "idle_expiry_seconds": -1 }'| Field | Description |
|---|---|
idle_expiry_seconds | Sets the seconds without activity before the idle action. Minimum: 60Maximum: 2147483647Value: -1 for no idle timeoutExample: 1800 |
on_idle_timeout | Sets the idle action. Value: delete, or stop for a persistent sandbox, and pause for a persistent Linux sandbox |
on_timeout | Sets the timeout action. Value: delete, or stop for a persistent sandbox, and pause for a persistent Linux sandbox |
timeout_seconds | Sets the seconds until the timeout, counted from now. Minimum: 1Maximum: 86400, unless the organization or its plan sets a different maximumExample: 3600 |
wake_on_request | Starts or resumes the sandbox when an authenticated toolbox, SSH, or private-preview request arrives. Rules: true only for a persistent Linux sandbox |
Delete
Delete a sandbox to remove it and release its resources. Deletion removes a resource permanently, together with the data stored only in it.
A deletion of a sandbox works in any state and discards its disk and memory once the teardown finishes, and cannot be undone. Images and snapshots captured from the sandbox remain after it is deleted.
Delete a sandbox when its work is done. To keep files from it, take a snapshot or write the files to a volume or other storage outside the sandbox first. The sandbox moves from deleting to deleted when the teardown finishes.
- Go to Daytona Sandboxes ↗
- Click the sandbox
- Click Delete
from daytona import Daytona
daytona = Daytona()
sandbox = daytona.v2.create()
sandbox.delete()
# Delete by sandbox ID, without fetching the sandbox first
daytona.v2.delete("{sandboxId}")| Parameter | Description |
|---|---|
sandbox | Sets the sandbox that daytona.v2.delete() deletes. Required Format: a sandbox handle or ID Example: sandbox |
timeout | Sets how many seconds the call waits for the sandbox to be deleted. Default: 60Value: 0 for no limitExample: 120 |
import { Daytona } from '@daytona/sdk'
const daytona = new Daytona()
const sandbox = await daytona.v2.create()
await sandbox.delete()
// Delete by sandbox ID, without fetching the sandbox first
await daytona.v2.delete('{sandboxId}')| Parameter | Description |
|---|---|
sandbox | Sets the sandbox that daytona.v2.delete() deletes. Required Format: a sandbox handle or ID Example: sandbox |
timeoutSeconds | Sets how many seconds the call waits for the sandbox to be deleted. Default: 60Value: 0 for no limitExample: 120 |
package main
import (
"context"
"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)
}
err = sandbox.Delete(ctx, nil)
if err != nil {
log.Fatal(err)
}
// Delete by sandbox ID, without fetching the sandbox first
err = client.Delete(ctx, "{sandboxId}", nil)
if err != nil {
log.Fatal(err)
}
}| Parameter | Description |
|---|---|
id | Sets the sandbox that client.Delete deletes. Required Format: a sandbox ID Example: sandbox.ID() |
Timeout | Sets how long the call waits for the sandbox to be deleted. Default: time.MinuteValue: daytona.NoWait to return once the delete is accepted, daytona.WaitForever for no limitExample: 2*time.Minute |
daytona sandbox delete {sandboxId} --yes| Flag | Description |
|---|---|
--no-wait | Returns once the server accepts the deletion. |
--timeout | Sets how long the command waits for the sandbox to be deleted. Default: 10mFormat: a Go duration greater than zero Example: 5m |
-y, --yes | Skips the confirmation prompt. |
curl 'https://api.daytona.com/sandboxes/{sandboxId}' \
--request DELETE \
--header 'Authorization: Bearer YOUR_API_KEY'