Lifecycle

A sandbox has four lifecycle events: on_create, on_delete, on_suspend, and on_resume. Custom scripts can be hooked into these events at the workspace level to perform custom logic during lifecycle transitions.

Definition

Add a lifecycle section to a workspace definition:

workspaces:
- name: dev
  checkouts:
  - path: tools
    repo:
      git: git@github.com:example-org/sandbox-tools
  lifecycle:
    on_create:
      require_build: true
      timeout: 10m
      max_retries: 5
      run:
        cmd: ./scripts/handle_sandbox_lifecycle.sh $SANDBOX_LIFECYCLE
        dir: tools
    on_delete:
      run:
        cmd: ./scripts/handle_sandbox_lifecycle.sh $SANDBOX_LIFECYCLE
        dir: tools
    on_suspend:
      run:
        cmd: ./scripts/handle_sandbox_lifecycle.sh $SANDBOX_LIFECYCLE
        dir: tools
    on_resume:
      run:
        cmd: ./scripts/handle_sandbox_lifecycle.sh $SANDBOX_LIFECYCLE
        dir: tools

Field reference:

Commands run as the owner user. The environment variable $SANDBOX_LIFECYCLE is set to the lifecycle event name.

Failures

Scripts are expected to exit with code 0 to indicate success. A non-zero exit code is treated as a failure.

A lifecycle hook failure blocks the corresponding lifecycle transition. For example:

Failures must be manually resolved. Use the Web UI or CLI:

cs sandbox lifecycle resolve -S sandbox -a skip dev1:retry

This skips all other failures in the sandbox and retries the hook on workload dev1.

Lifecycle States

Each workload inside a sandbox progresses through the following lifecycle states:

State Description
Creating Being created; on_create hook is running. Transitions to Running on success.
Running Running normally.
Suspending Being suspended; on_suspend hook is running. Transitions to Suspended on success.
Suspended Suspended.
Resuming Being resumed; on_resume hook is running. Transitions to Running on success.
Deleting Being deleted; on_delete hook is running. Transitions to Deleted on success.
Deleted Has been deleted.

Creating, Suspending, Resuming, and Deleting are transition states — they are expected to move to a stable state. Failures in lifecycle hooks cause the workload to remain in the transition state until resolved.

Auto Suspension Interaction

When Auto Suspension triggers while a workload is stuck in a transition state:

See Also