For AI agents: the complete documentation index is at https://www.daytona.com/llms.txt. Append .md to any docs page URL to get it as Markdown.

Sign Up
Docs v2.8
Skip to Content

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.

LifecycleLinuxWindowsmacOSGPU
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.

Sandbox states
StateAPI statusDescription
queuedqueuedThe create request is recorded and waits for its image before it is published for placement.
creatingpending, assignedThe sandbox waits for a host, and the host it is placed on prepares its image.
startingbootingThe virtual machine is booting and will be ready to use.
startedrunningThe sandbox is running and ready to accept requests.
pausingpausingThe sandbox is saving its memory and processes before it pauses.
pausedpausedThe memory, processes, and disk of a persistent sandbox are saved, and it accepts no requests.
stoppingstoppingThe virtual machine is shutting down.
stoppedstoppedThe virtual machine of a persistent sandbox is shut down, its disk is kept, and it accepts no requests.
destroyingdeletingThe sandbox is being deleted.
destroyeddeletedThe sandbox and its storage are removed.
errorfailed, lostThe image build, create, or boot failed, or the host or virtual machine of the sandbox was lost.
unknownThe SDK does not recognize the status the API reports.
State transitions
Initial stateTarget stateTrigger
queuedcreatingThe image is ready and the create request is published for placement.
creatingstartingThe host has prepared the image and boots the virtual machine.
startingstartedThe sandbox finishes booting and accepts requests.
startedstoppingA stop or a restart is requested, or a timeout with the stop action elapses.
stoppingstoppedThe virtual machine has shut down and the disk is kept.
startedpausingA pause is requested, or a timeout with the pause action elapses.
pausingpausedThe memory and processes are saved.
stopped, pausedcreatingA start or a resume is requested.
creating, starting, starteddestroyingA delete is requested, a timeout elapses, or the platform reclaims a spot sandbox.
queued, creating, stopped, paused, errordestroyedA delete is requested for a sandbox with no running virtual machine, so it skips destroying.
starteddestroyedThe virtual machine shuts down on its own.
destroyingdestroyedThe sandbox is removed and its resources are released.
queued, creating, startingerrorThe image build, create, or boot fails.
creating, starting, started, destroyingerrorThe 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.

main.py
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)
ParameterDescription
timeoutSets the wait limit in seconds.
Default: 60
Value: 0 for no limit
Example: 120
untilSets 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 destroyed
Example: "stopped"

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 typeRestartDiskStartReservation
Linux✓KeptBoots from the kept diskNone
Windows✓KeptBoots from the kept diskNone
macOS✗Kept on the same Mac, which keeps its disk room, while its cores, memory, and slot become available to other sandboxesBoots on any Mac of the organization that has room, and iCloud asks the user to sign in again after a move to a different MacA start with no reservation in the region buys one if auto-reserve is on. A stopped sandbox does not keep automatic renewal going
  1. Go to Daytona Sandboxes ↗
  2. Click the sandbox
  3. Click Stop
  4. Click Start
main.py
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)
ParameterDescription
timeoutSets how many seconds the call waits for the sandbox to reach the new state.
Default: 60
Value: 0 for no limit
Example: 120

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 typeVolumesResumeReservation
LinuxA sandbox with volumes attached cannot pauseContinues the processes with the same bootNone
macOSNot supportedContinues from the saved memory, or boots from the disk when the memory cannot be restored, and then reports mac_boot_mode cold_after_restore_failureA paused sandbox keeps its place on the reservation and counts as active, so its reservation keeps renewing
  1. Go to Daytona Sandboxes ↗
  2. Click the sandbox
  3. Click Pause
  4. Click Resume
main.py
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")
ParameterDescription
timeoutSets how many seconds the call waits for the sandbox to reach the new state.
Default: 60
Value: 0 for no limit
Example: 120

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 typeMemoryRunning sourcePaused or stopped source
LinuxCopied by default, which pauses the source brieflyThe fork starts on its own and continues the processes of the source, or boots fresh without memoryThe fork stays paused with memory, or stopped without, until it is resumed or started
macOSNever copied, and a request for memory failsThe fork boots with a new machine identityThe fork starts with a copy of the disk
  1. Go to Daytona Sandboxes ↗
  2. Click the sandbox
  3. Click Fork
main.py
from daytona import Daytona

daytona = Daytona()
sandbox = daytona.v2.create(persistent=True)

fork = sandbox.fork(name="agent-workspace-2")
ParameterDescription
memoryCopies the memory and running processes of the source into the fork.
Default: True on a Linux sandbox
Rules: not True on a macOS sandbox, which forks its disk only
nameSets 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_secondsSets how many seconds the call waits for the fork to settle.
Default: 60
Value: 0 for no wait
Example: 120

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.

TimeoutDefaultAction
Create3600 secondsDelete
LifetimeThe project's lifecycle default, otherwise 300 seconds, lowered to the organization's maximumDelete on an ephemeral sandbox, and an action of its type on a persistent one, with the default of its type
IdleNone, unless the project sets oneDelete on an ephemeral sandbox, and an action of its type on a persistent one, with no default
Sandbox typeDeleteStopPauseDefault for a persistent sandbox
Linux✓PersistentPersistentPause
Windows✓Persistent✗Stop
macOS✓Persistent✗Stop
GPU✓✗✗None, because a GPU sandbox is always ephemeral
ActivityIdle timeoutLifetime timeout
Request or connectionRestarts the countdown while it is openNo effect
CommandRestarts the countdown while a request for it, such as a wait, is openNo effect
Background commandNo effect once the request that started it returnsNo effect
Idle timer resetRestarts the countdownNo effect
main.py
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",
    },
)
ParameterDescription
create_timeout_secondsSets how many seconds the sandbox has to reach running before it is deleted.
Default: 3600
Minimum: 1
Maximum: 86400
Value: -1 for the maximum
Example: 600
lifecycle_policySets the timeouts of the sandbox.
Example: {"timeout_seconds": 3600, "on_timeout": "delete"}
timeout_secondsSets the wall-clock lifetime of the sandbox in seconds.
Default: the project's lifecycle default, otherwise 300, lowered to the organization's maximum
Minimum: 1
Maximum: 86400, unless the organization or its plan sets a different maximum
on_timeoutSets 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 sandbox
Value: "delete", or "stop" for a persistent sandbox, and "pause" for a persistent Linux sandbox
idle_expiry_secondsSets the seconds without activity before the idle action fires.
Default: none, unless the project sets one
Minimum: 60
Maximum: 2147483647
Rules: only with on_idle_timeout
Value: DISABLED for no idle timeout
on_idle_timeoutSets 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

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.

main.py
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)

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 typeActionsWake on request
LinuxDelete, and stop and pause on a persistent sandboxPersistent
WindowsDelete, and stop on a persistent sandbox✗
macOSDelete, and stop on a persistent sandbox✗
main.py
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)
ParameterDescription
idle_expiry_secondsSets the seconds without activity before the idle action.
Minimum: 60
Maximum: 2147483647
Value: DISABLED for no idle timeout
Example: 1800
on_idle_timeoutSets the idle action.
Value: "delete", or "stop" for a persistent sandbox, and "pause" for a persistent Linux sandbox
on_timeoutSets the timeout action.
Value: "delete", or "stop" for a persistent sandbox, and "pause" for a persistent Linux sandbox
timeout_secondsSets the seconds until the timeout, counted from now.
Minimum: 1
Maximum: 86400, unless the organization or its plan sets a different maximum
Example: 3600
wake_on_requestStarts 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.

  1. Go to Daytona Sandboxes ↗
  2. Click the sandbox
  3. Click Delete
main.py
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}")
ParameterDescription
sandboxSets the sandbox that daytona.v2.delete() deletes.
Required
Format: a sandbox handle or ID
Example: sandbox
timeoutSets how many seconds the call waits for the sandbox to be deleted.
Default: 60
Value: 0 for no limit
Example: 120