> ## Documentation Index
> Fetch the complete documentation index at: https://docs.microsandbox.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# VSock

> Connect a sandbox to host Unix sockets or local Windows named pipes over virtio-vsock with the Ruby SDK.

See [Host sockets](/networking/host-sockets) for guest connection details, platform support, and security considerations.

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

## SandboxBuilder

#### <span className="msb-recv">builder.</span><span className="msb-hn">vsock()</span>

```ruby theme={null}
builder.vsock(host_path, port) # => SandboxBuilder
```

<Accordion title="Example">
  ```ruby theme={null}
  sandbox = Microsandbox::Sandbox.builder("worker")
    .image("alpine")
    .vsock("/run/host-api.sock", 5000)
    .create
  ```
</Accordion>

Expose a host Unix stream socket or local Windows named pipe on host CID `2`. Call repeatedly to add routes; each socket type and port pair must be unique.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>host\_path</code><span className="msb-type">String</span></div>
    <div className="msb-param-desc">Absolute path to the host socket or pipe.</div>
  </div>

  <div className="msb-param">
    <div className="msb-param-key"><code>port</code><span className="msb-type">Integer</span></div>
    <div className="msb-param-desc">Port exposed to the guest.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><span className="msb-type">SandboxBuilder</span></div>
    <div className="msb-param-desc">The builder, for chaining.</div>
  </div>
</div>

#### <span className="msb-recv">builder.</span><span className="msb-hn">vsock\_dgram()</span>

```ruby theme={null}
builder.vsock_dgram(host_path, port) # => SandboxBuilder
```

Expose a host Unix datagram socket while preserving datagram boundaries. Datagram routes are unavailable on Windows. Call repeatedly to add routes; each socket type and port pair must be unique.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>host\_path</code><span className="msb-type">String</span></div>
    <div className="msb-param-desc">Absolute path to the host socket or pipe.</div>
  </div>

  <div className="msb-param">
    <div className="msb-param-key"><code>port</code><span className="msb-type">Integer</span></div>
    <div className="msb-param-desc">Port exposed to the guest.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><span className="msb-type">SandboxBuilder</span></div>
    <div className="msb-param-desc">The builder, for chaining.</div>
  </div>
</div>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.