Skip to main content
Create a sandbox, stop and restart it as needed, and remove it when you are finished. Stopping keeps its configuration and filesystem; removing deletes its saved state.

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.
Creating a sandbox starts it and waits until it is ready for commands. Give it a name so you can find it later. Names must be non-empty and no longer than 128 UTF-8 bytes.

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.
Use 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.
Use restart to stop and start in one operation. If the sandbox is already stopped or crashed, it starts directly.
CLI
If graceful shutdown times out, restart fails without starting a new VM. For a sandbox that will not stop, see Stop an unresponsive sandbox.

Reuse or create a named sandbox

Use connect_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
Creation options apply only to new sandboxes. An existing sandbox keeps its saved configuration. To recreate it with different settings, use replacement locally, or remove and recreate it on cloud.
If you already have a 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.
To detach a sandbox you already created, call 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

Use wait_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.
Use 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

Use msb 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.
See Live Modify for the change model, CPU and memory resize, labels, environment variables, secrets, and storage sizing.

Check health and keep a sandbox active

Ping and touch are currently available only for local sandboxes.
Use 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.
Use a drain when existing commands should finish but new commands should be rejected. The sandbox moves to Draining, waits for in-flight commands, and then stops. This is useful when rotating worker sandboxes without interrupting active jobs.

Destroy or remove

Use destroy 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.
Use remove when the sandbox is already stopped and you want to delete it by name.
For a local sandbox, removal deletes sandbox-owned state while leaving independently managed resources intact: 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 use connect_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.
If graceful stop does not work, use 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

Use msb logs or the SDK logs() method to read sandbox output, even after it stops or crashes. See Logs for troubleshooting startup and other failures.

Reference

For exact lifecycle APIs, see TypeScript, Rust, Python, or Go. For lifecycle commands and the REST surface, see Sandbox commands and the Cloud API.