Introducing a new way to review your PRs.

Read the announcement

arcboxlabs / arcbox

Run AI agents on real and isolated machines — own kernel, filesystem, and network — with <100ms boot. Local first, OCI compatible, pure Rust.

View on GitHub

32 documents · Updated Nov 6, 2026

docs / host-network-integration

Host network integration

Host network integration connects ArcBox guest Ethernet traffic to macOS network services and host I/O. It combines vmnet for Apple-managed virtual links, XNU-aware datagram transport for fast host-side frame exchange, and direct RX injection for efficient delivery into a running guest.

Integration model

ArcBox keeps guest networking as Ethernet frames until a platform boundary handles them. The Hypervisor.framework and Virtualization.framework paths use different host attachments, but both preserve the same guest-facing network model.

Platform network paths

The primary network path gives the guest outbound access through an ArcBox-managed data plane. That path supplies local network services such as DHCP and DNS and can proxy guest traffic through host sockets. A separate bridge path uses vmnet when the host must reach networks attached to another guest interface, such as container address ranges.

The main platform choices are:

PathHost facilityMain purpose
Managed NATArcBox data planeGuest outbound access with local DHCP, DNS, and protocol proxying
vmnet linkApple vmnet.frameworkShared, host-only, or bridged virtual networking
Direct RX injectionGuest memory and VirtIO RX queueFast host-to-guest frame delivery on the HV path

The related virtual networking and packet services page describes the guest packet services that sit above these platform paths.

References: virt/…/network.rs• L15-24 virt/…/network.rs• L237-249 virt/…/network.rs• L69-97

Frame boundaries

The host boundary uses datagram-style frame transport so one read or write represents one Ethernet frame. The data plane reads guest frames, classifies them, and sends replies through either a host file descriptor or an RX injection sink. This keeps protocol handling separate from the mechanism that moves frames between host and guest.

On the HV path, the primary VirtIO device binds a host descriptor for guest TX and keeps a separate RX channel for frames produced by the data plane. On the VZ file-handle path, the host side of a datagram socket is attached to the network device and the host data plane owns the network processing.

References: virt/…/mod.rs• L253-277 virt/…/mod.rs• L432-450 virt/…/mod.rs• L52-92

vmnet integration

vmnet is Apple's host service for creating virtual network interfaces on macOS. ArcBox presents it through a small platform boundary that chooses the link mode, records the interface properties, and exposes packet read and write operations to the VM path.

vmnet modes

The vmnet wrapper supports three link goals. Shared mode gives a VM access to the host network through NAT and vmnet-managed DHCP and DNS. Host-only mode limits traffic to the host and related virtual participants. Bridged mode places the VM on a named physical network as a separate Layer 2 device.

The configuration can also keep a stable MAC address and set the MTU. Shared mode can define the DHCP range and subnet. Host-only mode can request interface isolation when separate virtual networks must not share traffic.

References: virt/…/lib.rs• L1-24 virt/…/interface.rs• L37-56 virt/…/interface.rs• L73-149

vmnet bridge relay

The vmnet bridge relay makes vmnet look like a bidirectional Ethernet endpoint to the VM device. It drains packets from vmnet when macOS reports that packets are available. It sends guest frames to vmnet through asynchronous file-descriptor I/O.

The relay is a transparent Layer 2 pipe. vmnet owns the bridge-side DHCP, DNS, and ARP behavior for this path. The relay uses event notification rather than a polling thread, which keeps an idle bridge quiet and lets shutdown remove the native callback cleanly.

The HV bridge path creates a vmnet interface in shared mode, gives its MAC to a second VirtIO network device, and connects that device to the relay. This path is optional. If it cannot start, the rest of the guest network path can still provide outbound access, but host routing to the bridge network is not available.

References: virt/…/relay.rs• L1-24 virt/…/relay.rs• L165-185 virt/…/network.rs• L237-249 virt/…/network.rs• L374-413

vmnet lifecycle

Starting vmnet can fail when macOS rejects the configuration or the process lacks the required authorization. The interface reports its MAC, MTU, and maximum packet size after start so the connected network device can use matching link values.

Stopping first removes the packet event callback and then stops the interface. This order releases the native callback's retained context and prevents the callback from keeping the vmnet object alive during runtime shutdown.

References: virt/…/interface.rs• L194-203 virt/…/interface.rs• L310-381 virt/…/interface.rs• L485-589 virt/…/interface.rs• L644-725

XNU datagram transport

XNU networking support provides batched datagram I/O for host file descriptors. On macOS it uses XNU's batch message calls. On Linux it provides the matching standard batch calls so the shared transport contract remains usable outside macOS.

Batch frame I/O

arcbox-xnu-net treats a non-blocking datagram descriptor as a stream of complete frame units. It can receive or send many datagrams in one operation and returns the length of each received unit. Its async form joins these calls to Tokio readiness and retries after the descriptor reports that it would block.

This transport is used by the guest-bound write path and by the macOS frame source that feeds the classifier. The result is fewer host kernel crossings without changing the higher-level packet service flow.

References: common/…/lib.rs• L1-12 common/…/batch.rs• L43-66 common/…/async_batch.rs• L13-18 virt/…/guest_tx.rs• L20-27 common/…/frame_source.rs• L49-64

Readiness and capacity

The batch layer requires non-blocking descriptors. A receive returns WouldBlock when no frame is ready, and a send returns it when the peer cannot accept more frames. Readiness users must drain until that state and then wait for a new event.

macOS limits the number of datagrams that one batch call may pass. The transport reads the host limits and keeps each call within them. Receive slots must still be large enough for the largest possible frame because XNU can truncate an oversized datagram without a separate truncation signal.

References: common/…/batch.rs• L6-20 common/…/batch.rs• L120-155 common/…/batch.rs• L213-258 common/…/async_batch.rs• L46-105 common/…/frame_source.rs• L87-123

Guest-bound backpressure

Host-to-guest frame delivery distinguishes reliable TCP-shim frames from loss-tolerant datagram replies. Reliable frames remain queued when the guest endpoint is full. Datagram replies use a bounded queue because their protocols can recover from loss.

On macOS, a full datagram peer can report ENOBUFS instead of EAGAIN. The guest-bound path keeps the frame and uses a short retry timer for that case. This prevents a full guest RX path from turning into a silent TCP sequence gap.

References: virt/…/guest_tx.rs• L4-18 virt/…/guest_tx.rs• L29-42 virt/…/guest_tx.rs• L182-235 virt/…/mod.rs• L277-299

Network injection

Network injection is the host-to-guest delivery path for frames that the host data plane creates or receives. Instead of making the main event loop write every frame through a socketpair, the HV path can pass frames to a dedicated worker that writes them into the guest's VirtIO receive buffers.

RX injection flow

The injection worker starts when the primary VirtIO network device reaches DRIVER_OK. It receives ordinary frames from the data plane and can also receive promoted host TCP connections for direct data transfer. It publishes completed guest RX buffers and raises the guest network interrupt after each coalesced batch.

This diagram shows the host-to-guest path and the separate guest-to-host path.

flowchart LR
    HostNet[Host sockets or vmnet] --> DataPlane[ArcBox network data plane]
    DataPlane -->|frames| RxChannel[RX frame channel]
    RxChannel --> RxWorker[HV RX injection worker]
    RxWorker --> VirtioRx[Guest VirtIO RX queue]
    VirtioRx --> Guest[Guest network stack]
    Guest --> VirtioTx[Guest VirtIO TX queue]
    VirtioTx --> HostFd[Host datagram endpoint]
    HostFd --> DataPlane

References: virt/…/net_worker.rs• L18-40 virt/…/net_worker.rs• L118-245 virt/…/inject.rs• L1-12 virt/…/inject.rs• L78-96

Direct guest delivery

The injection worker owns the receive queue view for the VM lifetime and writes frame data into guest memory. It can merge a large host TCP read across several guest buffers. The guest sees the result as a normal VirtIO network frame while the host avoids an extra intermediate socket write.

The worker also preserves transport end states. A clean host end becomes a guest FIN. A host read error becomes a guest RST so the guest does not treat a truncated stream as complete or leave the connection stuck in an established state.

References: virt/…/inject.rs• L285-299 virt/…/inject.rs• L484-513 virt/…/inject.rs• L597-632

Injection selection

The channel-based injection path is the preferred HV path when the data plane provides an RX channel. A legacy non-blocking socketpair worker remains as a fallback when that channel is absent. Both paths share the same frame injection rules so queue completion and guest notification do not depend on which host transport was selected.

The VZ path normally keeps the file-handle socket boundary. Its network device configuration assigns the host a raw Layer 2 frame endpoint and leaves ARP, DHCP, DNS, and NAT work to the host data plane.

References: virt/…/net_worker.rs• L118-125 virt/…/net_worker.rs• L192-304 virt/…/network.rs• L82-97 virt/…/mod.rs• L94-113

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the vmnet interface MAC and the connected VirtIO bridge NIC MAC aligned. A mismatch can prevent host bridge forwarding from finding the guest device.
  • Keep vmnet callback registration and both callback-clear paths aligned. A change to relay shutdown must still release the native callback before vmnet stops.
  • Keep XNU batch receive slot sizes at or above the largest frame that the peer can send. A smaller slot can lose the tail without an error.
  • Keep the RX injection channel, queue snapshot, guest memory mapping, and interrupt hooks as one contract. Changing one without the DRIVER_OK worker setup can strand host frames.
  • Preserve the distinction between reliable TCP-shim frames and loss-tolerant datagram frames when changing guest-bound queue or backpressure behavior.

Important failure modes

TriggerConsequenceGuard
vmnet start lacks authorization or has invalid bridge configurationThe vmnet-backed interface does not start. Optional bridge routing is unavailable.Report the vmnet configuration error and treat the bridge NIC as optional in the HV setup path.
vmnet event callback is not cleared during relay or VM shutdownThe native callback can retain its context and keep the vmnet object alive.Clear the callback on relay exit and in Vmnet::stop; both operations are idempotent.
XNU receive slot is smaller than an incoming datagramThe frame is silently truncated and the remaining datagram is discarded.Size frame slots for the largest peer frame.
A batch send accepts only part of the queued framesThe accepted frames are already delivered while the rest remain pending.Remove only the accepted prefix and retry the remainder through the non-blocking send path.
Guest RX endpoint fills while a reliable frame is pendingDropping the frame creates a TCP sequence gap and can stall the flow.Preserve reliable frames and resume on the correct readiness or retry signal.
RX injection worker receives an upstream read errorThe guest can remain in an established state with incomplete data.Inject a TCP RST and mark the promoted connection for cleanup.

Key files

FileWhy to read it
virt/…/network.rsShows how the HV primary data plane and optional vmnet bridge NIC connect host descriptors to VirtIO devices.
virt/…/interface.rsDefines the vmnet link modes, interface properties, start and stop behavior.
virt/…/relay.rsShows the event-driven bidirectional vmnet-to-guest frame relay.
virt/…/mod.rsExplains how guest frames enter the host data plane and how host replies leave it.
virt/…/guest_tx.rsDefines guest-bound delivery classes, batching, and backpressure behavior.
common/…/batch.rsDefines the cross-platform batch datagram contract and macOS capacity rules.
common/…/frame_source.rsShows how non-blocking datagram frames are drained into the classifier.
virt/…/net_worker.rsOwns HV RX worker selection and the handoff of guest memory and queue state.
virt/…/inject.rsDefines direct host-to-guest RX injection and promoted TCP delivery.
virt/…/network.rsDescribes the VZ NAT and raw file-handle network attachments.