Back to Microsandbox

VSock

docs/sdk/python/vsock.mdx

0.6.171.6 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

python
from microsandbox import Sandbox

sandbox = await Sandbox.create(
    "worker",
    image="alpine",
    vsock={"/run/host-api.sock": 5000},
)

Sandbox.create()

ParameterTypeDefaultDescription
vsockMapping[str, int] | Sequence[VsockRoute] | NoneNoneHost IPC routes exposed on guest host-CID ports

A mapping creates stream routes. Use typed VsockRoute values for datagram routes or when the socket type should be explicit.

VsockRoute

python
VsockRoute(host_socket, port, socket_type=VsockSocketType.STREAM)

Frozen route configuration imported from microsandbox.

Class methodReturnsDescription
stream(host_socket, port)VsockRouteCreate a stream route
dgram(host_socket, port)VsockRouteCreate a datagram route

Datagram routes are unavailable on Windows. Host paths must be absolute, and each socket type and port pair must be unique.

VsockSocketType

String enum imported from microsandbox.

MemberValueDescription
STREAM"stream"Reliable, ordered byte stream; the default
DGRAM"dgram"Best-effort messages with preserved datagram boundaries