PENDING, moves to CREATING while the container is provisioned, and then enters RUNNING when the container is up.
The RUNNING state is when you can perform most operations, such as running commands with Sandbox.exec(). When the main process of the sandbox exits, the sandbox enters a terminal state such as COMPLETED (if the exit code is 0) or FAILED (if there was an error). A sandbox can also be TERMINATED if it is externally killed or if it exceeds its maximum lifetime.
Sandbox states
The following table summarizes the states of a sandbox:| State | Description |
|---|---|
| PENDING | Start accepted, waiting for scheduling |
| CREATING | Container is being provisioned |
| RUNNING | Container is up, ready for operations |
| COMPLETED | Main process exited with code 0 |
| FAILED | Startup or runtime error |
| TERMINATED | Externally killed or lifetime exceeded |
Wait for a sandbox to start
UseSandbox.wait() when you want to confirm that the sandbox starts (sandbox reached RUNNING state) successfully before performing other operations, or when you want to separate startup errors from later command errors.
For example, you might want to wait for the sandbox to fail early if there is a problem with the container image, network configuration, or other startup parameters before you upload files, install dependencies, or run a training script.
The following code snippet shows how to wait for a sandbox to start:
Wait for a sandbox to complete
UseSandbox.wait_until_complete() when the sandbox’s main process represents the full workload and you want to wait for that job to finish.
Sandbox.run("python", "train.py") and want the sandbox lifecycle to match that command’s execution.
When the main process exits, the sandbox enters a terminal state. A successful run typically ends in COMPLETED. If the process fails, the sandbox may enter FAILED.
Stop a sandbox
UseSandbox.stop() when you no longer need the sandbox, when you want to end a long-running process, or when you need to clean up resources before the sandbox reaches its maximum lifetime.