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 / virtual-networking-and-packet-services

Virtual networking and packet services

ArcBox gives each VM a virtual Ethernet link and carries guest traffic through host-side network services. The path supplies link setup, address and name services, packet dispatch, NAT state, proxy-aware egress, and return delivery so guest applications can reach host and external services through a controlled network boundary. This page is the guest-traffic view of networking and data plane; host network integration covers the host interfaces and routes that sit beyond this path.

Guest traffic path

The guest uses a normal Ethernet device. ArcBox receives the guest frame, selects the service or host connection that should handle it, and sends the result back as a guest-bound frame.

This diagram shows the common traffic shape across the VM backends.

flowchart LR
    G[Guest applications and kernel]
    V[virtio-net device]
    L[Virtual link\nTAP or socketpair]
    C[Packet classifier]
    A[ARP and DHCP]
    D[DNS service]
    E[TCP UDP and ICMP\negress]
    N[NAT and connection state]
    H[Host network]
    P[SOCKS5 or HTTP CONNECT\nproxy]
    R[Guest-bound reply frames]

    G -->|Ethernet TX| V --> L --> C
    C --> A
    C --> D
    C --> E
    E --> N --> H
    E --> P
    A --> R
    D --> R
    H --> N --> R
    P --> R
    R -->|Ethernet RX| V --> G

The virtual link is the frame boundary between the VM device and the network service. A Linux TAP device presents Ethernet frames through a host file descriptor. On macOS, the custom data path uses a datagram socketpair so the VZ or HV network device can exchange the same kind of raw Ethernet frames with the host service. The link keeps the guest-facing protocol stable while the host-side transport changes by platform. References: virt/…/tap.rs• L11-16, virt/…/tap.rs• L22-30, virt/…/darwin.rs• L292-334, virt/…/network.rs• L15-55

Virtio-net device

The virtio-net device is the guest-visible NIC. Guest transmit buffers become Ethernet frames for the link, and host replies become data in guest receive buffers. The device negotiates features such as the MAC address, MTU, checksum handling, segmentation, and multi-buffer receive delivery so larger traffic can cross the same interface without changing the guest API. References: virt/…/virtio_device.rs• L9-39, virt/…/virtio_device.rs• L45-92, virt/…/tx_rx.rs• L8-50

VM network attachments

The VM setup selects an attachment that matches the intended network boundary. The file-handle attachment gives the host direct frame access and therefore requires the host data path to provide ARP, DHCP, DNS, NAT, and proxy behavior. A framework NAT attachment delegates that network boundary to the platform. A vmnet-backed bridge path uses a relay when the VM needs frames to reach a host-managed bridge or container network. References: virt/…/network.rs• L69-97, virt/…/darwin.rs• L292-300, virt/…/network.rs• L237-243, virt/…/relay.rs• L1-17

Guest network identity

The guest needs an address, a gateway, a DNS server, and a link identity before normal traffic can work. ArcBox supplies these values through DHCP or through the network identity used when a VM is attached.

DHCP leases

DHCP turns a new guest into a usable network peer. The service allocates an address from a configured pool and returns the subnet mask, gateway, DNS server list, and lease time. It also keeps leases by client MAC and supports stable reservations, so a guest can repeat discovery without creating a second identity. References: virt/…/config.rs• L15-34, virt/…/server.rs• L54-70, virt/…/server.rs• L127-156, virt/…/server.rs• L159-216

Gateway and DNS identity

The gateway is both the guest's next hop and the address used for host-provided DNS in the custom path. The guest sends DNS queries to that gateway. Local names can resolve inside ArcBox, while external names continue to upstream DNS. References: virt/…/config.rs• L36-69, virt/…/nat.rs• L16-45, virt/…/nat.rs• L463-473, virt/…/network.rs• L162-173, virt/…/dns.rs• L247-263

Sandbox network identity

Sandbox VMs use a private IPv4 pool behind isolated point-to-point TAP links. Each sandbox has a lease and a deterministic link identity, while invariant attachment mode lets fresh and restored guests see the same fixed guest address. Host-side translation maps that fixed identity to the sandbox's pool address. References: virt/…/lib.rs• L1-19, virt/…/lib.rs• L152-179, virt/…/guest_network.rs• L75-107, virt/…/guest_network.rs• L112-137

Packet processing

Packet processing changes a stream of guest Ethernet frames into a small set of traffic classes. The classifier handles link-local needs inline and sends network traffic to the service that owns its protocol.

Frame classification

The classifier accepts Ethernet frames and learns the guest MAC from valid unicast traffic. ARP requests for the gateway receive a local reply. IPv4 packets are separated into TCP, DHCP, DNS, other UDP, and ICMP paths. IPv6 and unsupported Ethernet types are outside this path and are discarded rather than partly processed. References: common/…/classifier.rs• L1-16, common/…/classifier.rs• L267-305, common/…/classifier.rs• L307-431

TCP connection path

A new outbound TCP SYN is held until the host-side connection decision completes. ArcBox then presents the host connection to the guest through a synthesized TCP handshake. Established traffic can use a fast path that moves host data into guest-bound frames, while the guest kernel remains responsible for TCP semantics. References: common/…/classifier.rs• L45-58, common/…/classifier.rs• L337-395, virt/…/mod.rs• L20-22, common/…/egress.rs• L17-43

UDP and ICMP paths

UDP and ICMP frames are handled as datagrams rather than as a guest TCP stream. The host egress service creates the required reply frames and can send supported traffic directly through host sockets. UDP can use a SOCKS5 path when the host proxy supports it; HTTP CONNECT is a TCP-only option. References: virt/…/intercept.rs• L17-62, common/…/lib.rs• L10-15, common/…/udp.rs• L1-20, common/…/icmp.rs• L1-20

Host-bound frame delivery

Replies follow a separate host-to-guest path so packet work does not need to wait for the next guest transmit frame. Constructed frames go to a bounded frame sink or a direct receive injector. The injector writes them into guest receive buffers and publishes the guest-visible completion, while promoted TCP connections can read host sockets directly into those buffers. References: common/…/direct_rx.rs• L28-40, virt/…/inject.rs• L1-12, virt/…/inject.rs• L50-75, virt/…/inject.rs• L131-143

NAT and routing

NAT lets private guest addresses use an external host network without exposing those private addresses outside the VM boundary. Routing decides which virtual interface receives a packet, while NAT changes address and port values only when the traffic crosses the private-to-external boundary.

Connection tracking

Connection tracking is the memory of a NAT flow. It records the original five-tuple, the translated source port, the reverse lookup, the flow state, and recent activity. Outbound traffic creates or reuses a mapping. Return traffic must match that reverse mapping before ArcBox restores the guest destination; unrelated inbound traffic is dropped. Expired entries release the state. References: common/…/conntrack.rs• L19-49, common/…/conntrack.rs• L110-145, common/…/conntrack.rs• L396-459, common/…/translate.rs• L252-325

Packet translation

The NAT engine examines Ethernet-framed IPv4 TCP and UDP traffic. For an internal source it applies source NAT and updates the packet checksums. For a reply to the external address it performs reverse NAT from the tracked flow. Non-IPv4 and unsupported protocols pass through or are ignored by this engine rather than entering connection state. References: common/…/translate.rs• L111-177, common/…/translate.rs• L180-249, common/…/translate.rs• L255-324, virt/…/nat_backend.rs• L98-179

Linux NAT network

On Linux, the NAT network creates a private bridge with the guest gateway address and attaches one TAP endpoint per connected VM. It allocates endpoint addresses from the DHCP range, enables forwarding, and masquerades traffic on the selected external interface. Endpoint removal releases its address and removes its TAP from the bridge. References: virt/…/nat.rs• L16-45, virt/…/nat.rs• L106-123, virt/…/nat.rs• L238-253, virt/…/nat.rs• L284-320, virt/…/nat.rs• L360-425, virt/…/nat.rs• L428-450

Interface routing

The host routes packets between virtual interfaces and the outside network. On Linux, a bridge can join TAP endpoints and firewall rules can allow private-to-external forwarding, masquerade outbound traffic, and direct return traffic to the right guest. On macOS, vmnet and route management provide the host-side interface that reaches container or bridge networks. References: virt/…/bridge.rs• L66-101, virt/…/firewall.rs• L159-192, virt/…/firewall.rs• L377-399, virt/…/firewall.rs• L768-820, common/…/lib.rs• L263-359

Port forwarding

Port forwarding creates a host entry point for a guest service. A TCP or UDP listener accepts host traffic and sends it to the guest address and port. The reverse direction returns data to the original host client, which makes a guest service reachable without exposing the entire guest network. References: virt/…/port_forward.rs• L17-26, virt/…/port_forward.rs• L67-79, virt/…/port_forward.rs• L256-336, virt/…/port_forward.rs• L338-386

DNS and fake IP

DNS is also a control link for proxy-aware traffic. The guest asks the gateway to resolve a name, and the host records enough of the answer to recover that name when the guest later opens a connection to the returned address.

Host DNS forwarding

The host DNS forwarder answers registered local names and local-domain misses without sending them upstream. Other supported queries go to detected or configured upstream servers and are cached for a limited time. The same local-host table can be shared by the host service and the VM data path, so a registration has one visible result. References: virt/…/dns.rs• L247-293, virt/…/dns.rs• L333-368, virt/…/dns.rs• L404-427, common/…/lib.rs• L10-17

Guest DNS names

The guest DNS server resolves container and sandbox names before it forwards a query to the gateway. Compose services can have both a service-level alias and a container-level alias. Unknown names in the local domain return NXDOMAIN, which prevents an internal name from leaking to public DNS. References: guest/…/dns_server.rs• L1-9, guest/…/dns_server.rs• L195-263, guest/…/dns.rs• L37-60

Fake-IP resolution log

Fake IP means a proxy or VPN gives a domain a synthetic address, commonly from 198.18.0.0/15. The resolution log stores recent IP-to-domain results from upstream A records. When a TCP flow targets one of those addresses, the proxy path can use the original domain instead of trying to connect to the synthetic address. The log and the fake-IP allocator must be cleared as one unit when mappings are reset. References: common/…/dns_log.rs• L1-18, common/…/dns_log.rs• L26-40, common/…/dns_log.rs• L53-95, common/…/proxy_detect.rs• L22-40

Proxy egress

Proxy egress is the host-side choice between a direct connection and a tunnel. It lets guest traffic follow the host's VPN or proxy policy without routing a synthetic guest address through the host kernel as if it were real.

Proxy environment

ArcBox detects system HTTP, HTTPS, and SOCKS settings where the platform provides them and uses proxy environment variables as a fallback. It also detects the standard fake-IP range and keeps a domain bypass list. A gateway destination remains direct because it represents the host itself, not an address that a remote proxy can reach. References: common/…/proxy_detect.rs• L42-98, common/…/proxy_detect.rs• L101-137, common/…/egress.rs• L90-152

Tunnel selection

For a proxied flow, ArcBox prefers SOCKS5 because it supports the broadest traffic set and can resolve a domain at the proxy. It uses HTTP CONNECT when no SOCKS5 proxy is available. A known DNS-log domain becomes the tunnel target; an unknown destination uses its IP text. Bypass rules select direct egress instead. References: common/…/egress.rs• L117-152, common/…/egress.rs• L156-193, common/…/lib.rs• L1-15

Host and guest service proxies

The network proxy components carry data between guest-facing protocols and host resources. The network path uses TCP, UDP, and ICMP egress relays plus inbound listeners for port forwarding. Separate guest vsock proxies expose local Docker and Kubernetes sockets to host clients; these are service bridges rather than packet forwarding and do not replace the guest traffic path. References: common/…/inbound_relay.rs• L1-20, guest/…/proxy.rs• L1-18, guest/…/proxy.rs• L20-46, guest/…/proxy.rs• L142-175

Change checklist

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

  • Keep the guest-facing gateway, DHCP pool, DNS listen address, and classifier match aligned. A change in one can make the guest request a service that the host does not intercept.
  • Keep the virtio-net MTU, host frame sizing, guest MSS limits, and UDP fragmentation policy aligned. A larger host frame does not fit a smaller guest link.
  • Keep NAT reverse-key creation, deletion, and inbound lookup identical. Outbound connections can still appear healthy when return traffic is dropped.
  • Keep fake-IP allocation, DNS response logging, and proxy target recovery in sync. Clearing only one side can send a tunnel to a stale or synthetic address.
  • Keep the selected attachment and its service owner aligned. A file-handle attachment needs host ARP, DHCP, DNS, and egress handling; a platform NAT attachment does not provide those services through ArcBox's custom loop.
  • Keep Linux NAT subnet, gateway, DHCP range, bridge, and external interface values aligned. The bridge provides the guest gateway while firewall masquerade must cover the same private network.
  • Keep port-forward targets consistent with the active guest identity. Invariant sandbox addresses and pool addresses may need different host ingress targets.

Important failure modes

TriggerConsequenceGuard
Guest uses an address outside the NAT engine's configured internal networkOutbound traffic passes without NAT and does not reach the expected external pathSet the engine's internal network to the guest subnet and keep DHCP and NAT ranges aligned.
Linux NAT bridge or firewall setup does not use the configured guest subnet and external interfaceThe guest may receive an address but cannot reach the external networkKeep bridge gateway, DHCP pool, forwarding rules, and masquerade configuration on the same network boundary.
Return packet has no matching connection-tracking entryInbound packet is dropped even though the outbound connection was createdPreserve the same reverse tuple at flow creation, removal, and inbound lookup.
Host proxy is given a fake IP without its DNS nameThe proxy may try to resolve or connect to a synthetic addressRecord upstream A answers and pass the recovered domain to tunnel selection.
File-handle attachment starts without host packet servicesThe guest can send frames but receives no usable DHCP, DNS, ARP, or external repliesStart the custom data path with its DHCP server, DNS forwarder, and egress handlers.
Guest-bound frame exceeds the negotiated link or peer MSSThe guest cannot accept or forward the frame, causing stalls or retransmitsSize injection and TCP segmentation from the active MTU and advertised peer MSS.
A TAP or bridge remains after a failed network lifecycleA later VM can collide with old addresses, routes, or forwarding rulesRemove link and translation state before returning an address to the pool.

Key files

FileWhy to read it
virt/…/darwin.rsShows how the VZ VM gets its file-handle network attachment and starts the custom packet services.
virt/…/network.rsShows the HV socketpair path and the separate vmnet bridge NIC path.
common/…/classifier.rsDefines the high-level split from guest Ethernet frames to ARP, DHCP, DNS, TCP, UDP, and ICMP handling.
virt/…/mod.rsShows how the classifier, service handlers, proxy egress, and guest reply delivery run as one loop.
virt/…/intercept.rsShows the DHCP and DNS service boundaries and how DNS results feed proxy-aware TCP.
virt/…/nat.rsDefines Linux NAT network identity, bridge and endpoint lifecycle, address allocation, and the gateway/DNS relationship.
common/…/translate.rsDefines the outbound SNAT and inbound reverse-NAT behavior.
common/…/conntrack.rsDefines the flow identity and state that NAT needs for return traffic.
virt/…/nat_backend.rsConnects virtio-net packet movement to the NAT engine and host packet I/O.
virt/…/server.rsDefines guest address allocation and DHCP lease behavior.
virt/…/dns.rsDefines host local-name resolution, upstream forwarding, and DNS caching.
common/…/dns_log.rsExplains how DNS results recover names for fake-IP proxy connections.
common/…/egress.rsDefines direct, SOCKS5, and HTTP CONNECT egress selection.
virt/…/inject.rsShows the host-to-guest receive path for constructed frames and promoted TCP data.
virt/…/guest_network.rsDefines sandbox leases, guest network identity, and host ingress targeting for TAP networks.