Back to Microsandbox

VSock

docs/sdk/rust/vsock.mdx

0.6.171.7 KB
Original Source

Expose a host Unix socket or local Windows named pipe to a sandbox over virtio-vsock. See VSock for guest connection details, platform support, and security considerations.

<Note>VSock routes are local-only and unavailable with the multi-tenant deployment profile.</Note>

Typical flow

rust
use microsandbox::Sandbox;

let sandbox = Sandbox::builder("worker")
    .image("alpine")
    .vsock("/run/host-api.sock", 5000)
    .create()
    .await?;

SandboxBuilder

vsock()

rust
fn vsock(self, host_path: impl AsRef<Path>, port: u32) -> Self

Expose a host Unix stream socket or local Windows named pipe on host CID 2 at port.

vsock_dgram()

rust
fn vsock_dgram(self, host_path: impl AsRef<Path>, port: u32) -> Self

Expose a host Unix datagram socket while preserving datagram boundaries. Datagram routes are unavailable on Windows.

vsock_route()

rust
fn vsock_route(self, route: VsockRouteSpec) -> Self

Add a fully specified route using VsockRouteSpec.

VsockRouteSpec

Import path: microsandbox::sandbox::VsockRouteSpec.

FieldTypeDescription
host_socketPathBufExisting Unix socket or local Windows named-pipe path
portu32Guest-facing port on host CID 2
socket_typeVsockSocketTypeStream or Dgram message semantics

Host paths must be absolute, and each socket type and port pair must be unique.

VsockSocketType

Import path: microsandbox::sandbox::VsockSocketType.

VariantDescription
StreamReliable, ordered byte stream; the default
DgramBest-effort messages with preserved datagram boundaries