Skip to content

Instantly share code, notes, and snippets.

@louis030195
Created December 6, 2025 21:58
Show Gist options
  • Select an option

  • Save louis030195/95ceac63a1b93928bcc2204a2d141075 to your computer and use it in GitHub Desktop.

Select an option

Save louis030195/95ceac63a1b93928bcc2204a2d141075 to your computer and use it in GitHub Desktop.
Windows Sandbox Architecture - Low Level API Layers

Windows Sandbox - Low Level Architecture

API Layer Diagram

┌─────────────────────────────────────────────────────────────────────────────┐
│                           USER MODE (Host)                                  │
├─────────────────────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────────────────┐  │
│  │ WindowsSandbox  │  │  Windows        │  │  WSB Config Parser          │  │
│  │     .exe        │──│  Defender       │  │  (.wsb XML files)           │  │
│  └────────┬────────┘  └─────────────────┘  └─────────────────────────────┘  │
│           │                                                                 │
│           ▼                                                                 │
│  ┌─────────────────────────────────────────────────────────────────────────┐│
│  │              HCS - Host Compute Service (vmcompute.dll)                 ││
│  │         High-level API for container/VM lifecycle management            ││
│  └────────┬────────────────────────────────────────────────────────────────┘│
│           │                                                                 │
│           ▼                                                                 │
│  ┌─────────────────────────────────────────────────────────────────────────┐│
│  │              HNS - Host Network Service (hns.dll)                       ││
│  │              Virtual switch, NAT, container networking                  ││
│  └────────┬────────────────────────────────────────────────────────────────┘│
│           │                                                                 │
│           ▼                                                                 │
│  ┌──────────────────┐  ┌──────────────────┐  ┌──────────────────────────┐   │
│  │ vmwp.exe         │  │ vmcompute.exe    │  │ CExecSvc.exe             │   │
│  │ (VM Worker Proc) │  │ (Compute Svc)    │  │ (Container Exec Agent)   │   │
│  └────────┬─────────┘  └────────┬─────────┘  └──────────────────────────┘   │
│           │                     │                                           │
├───────────┴─────────────────────┴───────────────────────────────────────────┤
│                          KERNEL MODE (Host)                                 │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                    WHP - Windows Hypervisor Platform                  │  │
│  │                         (vid.dll / vid.sys)                           │  │
│  │            User-mode API to create/manage VM partitions               │  │
│  └────────┬──────────────────────────────────────────────────────────────┘  │
│           │                                                                 │
│           ▼                                                                 │
│  ┌────────────────────┐  ┌────────────────────┐  ┌──────────────────────┐   │
│  │ wcifs.sys          │  │ bindflt.sys        │  │ wc_storage.sys       │   │
│  │ Container          │  │ Bind Filter        │  │ Container Storage    │   │
│  │ Isolation FS       │  │ (folder mapping)   │  │ Driver               │   │
│  │ (copy-on-write)    │  │                    │  │                      │   │
│  └────────┬───────────┘  └────────┬───────────┘  └──────────┬───────────┘   │
│           │                       │                         │               │
│           ▼                       ▼                         ▼               │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                         ntoskrnl.exe                                  │  │
│  │    ┌─────────────┐  ┌─────────────┐  ┌─────────────┐  ┌───────────┐   │  │
│  │    │ Ob Manager  │  │ I/O Manager │  │ Mm Manager  │  │ Ps Manager│   │  │
│  │    │ (Objects)   │  │ (File I/O)  │  │ (Memory)    │  │ (Process) │   │  │
│  │    └─────────────┘  └─────────────┘  └─────────────┘  └───────────┘   │  │
│  └────────┬──────────────────────────────────────────────────────────────┘  │
│           │                                                                 │
│           ▼                                                                 │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                      dxgkrnl.sys (GPU-PV)                             │  │
│  │              DirectX kernel - GPU paravirtualization                  │  │
│  │              Marshals GPU calls between host/guest                    │  │
│  └───────────────────────────────────────────────────────────────────────┘  │
│                                                                             │
├─────────────────────────────────────────────────────────────────────────────┤
│                         HYPERVISOR (Ring -1)                                │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                    hvix64.exe / hvax64.exe                            │  │
│  │                  Windows Hypervisor (Hyper-V)                         │  │
│  │  ┌─────────────────────────────────────────────────────────────────┐  │  │
│  │  │  Partition Management  │  Memory Virtualization (EPT/NPT)      │  │  │
│  │  │  VMCS/VMCB handling    │  Interrupt Virtualization (APIC-V)    │  │  │
│  │  │  Hypercall Interface   │  Device Emulation (synthetic devices) │  │  │
│  │  └─────────────────────────────────────────────────────────────────┘  │  │
│  └───────────────────────────────────────────────────────────────────────┘  │
│                                                                             │
├─────────────────────────────────────────────────────────────────────────────┤
│                              HARDWARE                                       │
├─────────────────────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────────────────┐  │
│  │ Intel VT-x /    │  │ SLAT            │  │ TPM 2.0                     │  │
│  │ AMD-V           │  │ (EPT/NPT)       │  │ (optional, for security)    │  │
│  │ CPU Virt Ext    │  │ Memory Virt     │  │                             │  │
│  └─────────────────┘  └─────────────────┘  └─────────────────────────────┘  │
└─────────────────────────────────────────────────────────────────────────────┘

Inside the Sandbox VM

┌─────────────────────────────────────────────────────────────────────────────┐
│                        SANDBOX GUEST (Isolated)                             │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────────────────┐  │
│  │ explorer.exe    │  │ User Apps       │  │ Mapped Folders (read-only   │  │
│  │ (Desktop Shell) │  │ (untrusted)     │  │ or read-write via bindflt)  │  │
│  └────────┬────────┘  └────────┬────────┘  └─────────────────────────────┘  │
│           │                    │                                            │
│           ▼                    ▼                                            │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                    win32k.sys (Guest)                                 │  │
│  │                    Window Manager / GDI                               │  │
│  └────────┬──────────────────────────────────────────────────────────────┘  │
│           │                                                                 │
│           ▼                                                                 │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                    ntoskrnl.exe (Guest Kernel)                        │  │
│  │              Separate kernel instance, own page tables                │  │
│  └────────┬──────────────────────────────────────────────────────────────┘  │
│           │                                                                 │
│           ▼                                                                 │
│  ┌────────────────────┐  ┌────────────────────┐  ┌──────────────────────┐   │
│  │ storvsp.sys        │  │ vmbus.sys          │  │ netvsp.sys           │   │
│  │ (Storage VSP)      │  │ (VMBus Client)     │  │ (Network VSP)        │   │
│  │ → Host storage     │  │ → Hypercalls       │  │ → Host NIC           │   │
│  └────────────────────┘  └────────────────────┘  └──────────────────────┘   │
│                                                                             │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │              Synthetic Devices (via VMBus to host)                    │  │
│  │   ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────────┐   │  │
│  │   │ Keyboard │ │  Mouse   │ │  Video   │ │  Disk    │ │  Network  │   │  │
│  │   └──────────┘ └──────────┘ └──────────┘ └──────────┘ └───────────┘   │  │
│  └───────────────────────────────────────────────────────────────────────┘  │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Data Flow: File Access (Copy-on-Write Magic)

  Sandbox App                                              Host Filesystem
  reads C:\Windows\System32\ntdll.dll                      C:\Windows\System32
       │                                                          │
       ▼                                                          │
  ┌─────────────┐                                                 │
  │ Guest NTFS  │                                                 │
  └──────┬──────┘                                                 │
         │ (file not in writable layer)                           │
         ▼                                                        │
  ┌─────────────┐      VMBus       ┌─────────────┐               │
  │ storvsp.sys │ ───────────────► │ storvsc.sys │               │
  └─────────────┘    hypercall     └──────┬──────┘               │
                                          │                       │
                                          ▼                       │
                                   ┌─────────────┐               │
                                   │ wcifs.sys   │ ◄─────────────┘
                                   │ (resolves   │   direct link
                                   │  to host)   │   (no copy!)
                                   └─────────────┘

Key Components Summary

Layer Component Purpose
User Mode WindowsSandbox.exe Main launcher, parses .wsb config
User Mode vmcompute.dll (HCS) Host Compute Service - VM/container lifecycle
User Mode hns.dll (HNS) Host Network Service - virtual networking
User Mode vmwp.exe VM Worker Process - per-VM host process
Kernel vid.sys Virtualization Infrastructure Driver
Kernel wcifs.sys Container Isolation FS - copy-on-write magic
Kernel bindflt.sys Bind filter - folder mapping to sandbox
Kernel dxgkrnl.sys GPU paravirtualization (GPU-PV)
Hypervisor hvix64.exe Intel Hyper-V hypervisor
Hypervisor hvax64.exe AMD Hyper-V hypervisor
Guest vmbus.sys VMBus client - hypercall interface
Guest storvsp.sys Storage virtualization service provider

Why It's Fast

  1. No OS Copy: wcifs.sys links directly to host binaries
  2. Memory Dedup: Hyper-V shares identical pages between host/guest
  3. GPU-PV: Near-native GPU via dxgkrnl.sys marshaling
  4. Ephemeral: No disk persistence = instant cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment