Create a sandbox
By default, sandboxes created through a local SDK stop when your application exits. To keep one running, detach it. Cloud sandboxes keep running until stopped or removed, subject to their lifetime limits.
Pause and resume
Pause freezes a local sandbox in memory. Resume continues where it left off. New commands are rejected while paused, and network connections may time out. Pause and resume are not supported on cloud. Time spent paused does not count toward the 60-second limit for waiting input. If new connections were already blocked, they stay blocked until input starts flowing again.resume for a paused sandbox and start for a stopped one. Repeating pause or resume is safe. Pausing does not create a snapshot; taking a full snapshot while paused leaves it paused. Pause/resume requires a matching runtime and guest kernel.
Stop and start again
Stopping shuts down the sandbox and its processes while keeping its configuration and filesystem. Starting it again boots a new VM; it does not resume the old processes.stop() waits for graceful shutdown with no default timeout. Use your SDK’s stop-with-timeout method to limit the wait. A timeout returns an error without force-killing; the shutdown may still finish later. Resume a paused sandbox before stopping it.
See the SDK references for timeout options and cancellation rules: TypeScript, Rust, Python, or Go. Cancelling a wait does not disable automatic cleanup or lifetime limits.
restart to stop and start in one operation. If the sandbox is already stopped or crashed, it starts directly.
CLI
Reuse or create a named sandbox
Useconnect_or_create to reuse a named sandbox or create it if it does not exist.
The operation:
- Connects if the sandbox is running
- Starts it if it is stopped or crashed
- Creates it if the name does not exist
SandboxHandle, use connect_or_start to connect to that exact sandbox or start it when needed.
Keep a sandbox running
Detach a local sandbox when it should keep running after the client process exits. You can reconnect to it later by name.detach() (Detach in Go).
List and inspect
List sandboxes to discover what exists, or get one by name when you already know which sandbox you need.Wait for a state
Usewait_until_stopped to wait for a sandbox to stop without requesting a shutdown yourself. To request shutdown now and wait separately, use request_stop first; see your SDK reference for the method names.
wait_for_status (waitForStatus in TypeScript and WaitForStatus in Go) when you need to wait for a specific lifecycle state. It has no built-in timeout, so use the language’s normal timeout or cancellation primitive around it.
Change configuration
Usemsb modify, or the SDK modify() methods, to change an existing sandbox without recreating it. Some changes apply immediately, some affect future commands, and some take effect after a restart.
Check health and keep a sandbox active
Ping and touch are currently available only for local sandboxes.
ping to check that a running sandbox’s guest agent is reachable. A ping is only a health check and does not reset the idle timer. Use touch when you intentionally want to keep the sandbox active.
Drain before stopping
Draining is currently available only for local sandboxes. Use a graceful stop on microsandbox cloud.
Draining, waits for in-flight commands, and then stops. This is useful when rotating worker sandboxes without interrupting active jobs.
Destroy or remove
Usedestroy to stop and remove a sandbox in one operation. If graceful shutdown times out, it leaves the saved data intact. It will not remove a different sandbox that has reused the same name.
remove when the sandbox is already stopped and you want to delete it by name.
Removing a sandbox does not undo writes made to a named volume, bind mount, or user-supplied disk image. On cloud, removal deletes the remote sandbox resource; the local disk details above do not apply.
Automatic lifecycle policies
For production workloads, configure a maximum lifetime or idle timeout so sandboxes shut down automatically.Lifecycle states
Use these states to display status or decide what to do next.Names, handles, and concurrent callers
A name identifies the sandbox currently saved under it. An SDK handle identifies one specific sandbox. If that sandbox is removed and its name is reused, the old handle will not act on the replacement. Concurrent callers can safely useconnect_or_create or connect_or_start to reuse a sandbox. If it is still starting, they wait rather than start another VM. See your SDK reference for identity checks and replacement errors.
Troubleshooting
Stop an unresponsive sandbox
Force kill is currently available only for local sandboxes. Use a graceful stop on microsandbox cloud.
kill to end the VM immediately. Running work is interrupted and unsaved data may be lost.
When input gets stuck
If input has to wait because the sandbox’s input queue has been full for 60 seconds, Microsandbox stops accepting new connections. It keeps existing connections and pending requests open, and output and logs remain available. It does not stop the sandbox or its workloads. New connections are accepted again once input starts flowing. You can set request timeouts in your application. A timeout does not necessarily mean the request failed to run.Logs and diagnostics
Usemsb logs or the SDK logs() method to read sandbox output, even after it stops or crashes. See Logs for troubleshooting startup and other failures.