Static methods
Sandbox::builder()
SandboxBuilder for all available options.
Parameters
| Name | Type | Description |
|---|---|---|
| name | impl Into<String> | Sandbox name - must be unique among running sandboxes |
| Type | Description |
|---|---|
SandboxBuilder | Builder for configuring the sandbox |
Sandbox::get()
| Name | Type | Description |
|---|---|---|
| name | &str | Sandbox name |
| Type | Description |
|---|---|
SandboxHandle | Handle with status and lifecycle control |
Sandbox::list()
| Type | Description |
|---|---|
Vec<SandboxHandle> | All sandbox handles |
Sandbox::remove()
| Name | Type | Description |
|---|---|---|
| name | &str | Sandbox name |
Sandbox::start()
| Name | Type | Description |
|---|---|---|
| name | &str | Name of a stopped sandbox |
| Type | Description |
|---|---|
Sandbox | Running sandbox |
Sandbox::start_detached()
| Name | Type | Description |
|---|---|---|
| name | &str | Name of a stopped sandbox |
| Type | Description |
|---|---|
Sandbox | Running sandbox |
Instance methods
config()
| Type | Description |
|---|---|
&SandboxConfig | Sandbox configuration |
detach()
Sandbox::get().
drain()
exec calls are rejected. The sandbox transitions to Stopped when all in-flight commands finish. Useful for zero-downtime rotation of worker sandboxes.
fs()
| Type | Description |
|---|---|
SandboxFs | Filesystem handle |
kill()
metrics()
| Type | Description |
|---|---|
SandboxMetrics | Resource metrics |
metrics_stream()
interval duration.
Parameters
| Name | Type | Description |
|---|---|---|
| interval | Duration | Time between metric snapshots |
| Type | Description |
|---|---|
impl Stream<Item = Result<SandboxMetrics>> | Async stream of metrics |
name()
| Type | Description |
|---|---|
&str | Sandbox name |
owns_lifecycle()
true in attached mode (sandbox stops when your process exits), false in detached mode.
Returns
| Type | Description |
|---|---|
bool | true if attached |
remove_persisted()
stop()
stop_and_wait()
| Type | Description |
|---|---|
ExitStatus | Exit code and success flag |
wait()
| Type | Description |
|---|---|
ExitStatus | Exit code and success flag |
SandboxBuilder
Builder for configuring a sandbox before creation. Obtained viaSandbox::builder(name).
cpus()
1.
Parameters
| Name | Type | Description |
|---|---|---|
| count | u8 | Number of vCPUs |
create()
| Type | Description |
|---|---|
Sandbox | Running sandbox |
create_detached()
| Type | Description |
|---|---|
Sandbox | Running sandbox |
disable_network()
entrypoint()
| Name | Type | Description |
|---|---|---|
| cmd | impl IntoIterator<Item = impl Into<String>> | Entrypoint command and arguments |
env()
exec_with) are merged on top.
Parameters
| Name | Type | Description |
|---|---|---|
| key | impl Into<String> | Variable name |
| value | impl Into<String> | Variable value |
hostname()
| Name | Type | Description |
|---|---|---|
| hostname | impl Into<String> | Hostname |
idle_timeout()
| Name | Type | Description |
|---|---|---|
| secs | u64 | Idle timeout in seconds |
image()
| Name | Type | Description |
|---|---|---|
| image | impl IntoImage | OCI image name, local directory path, or disk image path |
image_with()
| Name | Type | Description |
|---|---|---|
| f | ImageBuilder | Configure the disk image rootfs. |
log_level()
| Name | Type | Description |
|---|---|---|
| level | LogLevel | Log level |
max_duration()
| Name | Type | Description |
|---|---|---|
| secs | u64 | Maximum lifetime in seconds |
memory()
512 MiB.
Parameters
| Name | Type | Description |
|---|---|---|
| size | impl Into<Mebibytes> | Memory in MiB |
network()
| Name | Type | Description |
|---|---|---|
| f | NetworkBuilder | Configure the network. |
patch()
| Name | Type | Description |
|---|---|---|
| f | PatchBuilder | Configure rootfs patches. |
port()
| Name | Type | Description |
|---|---|---|
| host_port | u16 | Port on the host |
| guest_port | u16 | Port inside the sandbox |
port_udp()
| Name | Type | Description |
|---|---|---|
| host_port | u16 | Port on the host |
| guest_port | u16 | Port inside the sandbox |
pull_policy()
| Name | Type | Description |
|---|---|---|
| policy | PullPolicy | Pull behavior |
registry_auth()
| Name | Type | Description |
|---|---|---|
| auth | RegistryAuth | Registry credentials |
replace()
script()
/.msb/scripts/ inside the guest. Scripts are added to PATH and can be called by name via exec() or shell().
Parameters
| Name | Type | Description |
|---|---|---|
| name | impl Into<String> | Script name (becomes the filename) |
| content | impl Into<String> | Script content |
secret()
| Name | Type | Description |
|---|---|---|
| f | SecretBuilder | Configure the secret. |
secret_env()
.secret(|s| s.env(env_var).value(value).allow_host(allowed_host)).
Parameters
| Name | Type | Description |
|---|---|---|
| env_var | impl Into<String> | Environment variable name |
| value | impl Into<String> | Secret value |
| allowed_host | impl Into<String> | Allowed destination host |
shell()
Sandbox::shell(). Default: /bin/sh.
Parameters
| Name | Type | Description |
|---|---|---|
| shell | impl Into<String> | Shell path (e.g. "/bin/bash") |
user()
| Name | Type | Description |
|---|---|---|
| user | impl Into<String> | User name or UID |
volume()
| Name | Type | Description |
|---|---|---|
| guest_path | impl Into<String> | Mount point inside the sandbox |
| f | MountBuilder | Configure the mount. |
workdir()
| Name | Type | Description |
|---|---|---|
| path | impl Into<String> | Absolute path inside the guest |
Types
LogLevel
Sandbox process log verbosity.| Value | Description |
|---|---|
Error | Errors only |
Warn | Warnings and errors only |
Info | Info and higher |
Debug | Debug and higher |
Trace | Most verbose - all diagnostic output |
PullPolicy
Controls when the SDK fetches an OCI image from the registry.| Value | Description |
|---|---|
Always | Pull the image every time, even if cached locally |
IfMissing | Pull only if the image is not already cached. This is the default. |
Never | Never pull; fail if the image is not cached locally |
RegistryAuth
Credentials for authenticating to a private container registry.| Variant | Fields | Description |
|---|---|---|
Basic | - username: String - password: String | Username and password authentication |
SandboxConfig
The full configuration of a sandbox. Obtained viaconfig() or built via SandboxBuilder. Contains all settings used to create the sandbox.
| Field | Type | Description |
|---|---|---|
| cpus | u8 | Number of virtual CPUs |
| env | Vec<(String, String)> | Environment variables |
| idle_timeout_secs | Option<u64> | Idle timeout |
| image | RootfsSource | Root filesystem source (OCI, bind, or disk image) |
| max_duration_secs | Option<u64> | Maximum lifetime |
| memory_mib | u32 | Guest memory in MiB |
| name | String | Sandbox name |
| patches | Vec<Patch> | Rootfs patches |
| scripts | Vec<(String, String)> | Named scripts |
| shell | Option<String> | Shell for shell() calls |
| volumes | Vec<VolumeMount> | Volume mounts |
| workdir | Option<String> | Default working directory |
SandboxHandle
A lightweight handle to an existing sandbox (running or stopped). Obtained viaSandbox::get() or Sandbox::list(). Provides status, configuration, and lifecycle control without an active connection to the guest agent. You cannot exec or fs on a handle - call .start() or .connect() to upgrade to a full Sandbox.
| Property / Method | Type | Description |
|---|---|---|
| config() | Result<SandboxConfig> | Parsed configuration |
| config_json() | &str | Raw JSON configuration |
| connect() | Result<Sandbox> | Connect to a running sandbox |
| created_at() | Option<DateTime<Utc>> | Creation timestamp |
| kill() | Result<()> | Force terminate |
| metrics() | Result<SandboxMetrics> | Point-in-time resource metrics |
| name() | &str | Sandbox name |
| remove() | Result<()> | Delete sandbox and state |
| start() | Result<Sandbox> | Start in attached mode |
| start_detached() | Result<Sandbox> | Start in detached mode |
| status() | SandboxStatus | Current status |
| stop() | Result<()> | Graceful shutdown |
| updated_at() | Option<DateTime<Utc>> | Last update timestamp |
SandboxMetrics
Point-in-time resource usage snapshot.| Field | Type | Description |
|---|---|---|
| cpu_percent | f32 | CPU usage as a percentage |
| disk_read_bytes | u64 | Total bytes read from disk since boot |
| disk_write_bytes | u64 | Total bytes written to disk since boot |
| memory_bytes | u64 | Current memory usage in bytes |
| memory_limit_bytes | u64 | Memory limit in bytes |
| net_rx_bytes | u64 | Total bytes received over the network since boot |
| net_tx_bytes | u64 | Total bytes sent over the network since boot |
| timestamp | DateTime<Utc> | When this measurement was taken |
| uptime | Duration | Time since the sandbox was created |
SandboxStatus
| Value | Description |
|---|---|
Crashed | VM exited unexpectedly (kernel panic, OOM, etc.) |
Draining | Graceful shutdown in progress; existing commands finish, new ones rejected |
Running | Guest agent is ready; exec, shell, fs work |
Stopped | VM shut down; configuration persisted; can be restarted |