How to Configure Windows Sandbox Local NATS Messaging Server via XML in Windows 11

Modern microservice architectures, event-driven backends, and edge computing platforms frequently rely on NATS for ultra-low-latency publish/subscribe messaging, request-reply semantics, and JetStream persistence. Testing NATS subject hierarchies, stream retention policies, and consumer ack timeouts directly on a developer workstation often causes port conflicts (port 4222/8222) and leaves persistent JetStream storage on local disks. In Windows 11, Windows Sandbox provides a pristine, isolated testing platform. By authoring custom Windows Sandbox XML (.wsb) configuration files, you can deploy a standalone NATS server in seconds.

Architecture of the Disposable NATS Sandbox

Windows Sandbox provides a disposable, hypervisor-isolated guest environment that resets completely upon termination. To provision an automated NATS instance, the architecture requires:

  • A mapped host folder: A directory containing the single nats-server.exe binary and custom configuration files.
  • A WSB configuration file: An XML blueprint that mounts the mapped directory and initiates the messaging daemon automatically via LogonCommand.

Authoring the Windows Sandbox WSB Blueprint

Create a working directory on your host machine, such as C:\SandboxNATS. Download the Windows binary of nats-server.exe into this directory, then create RunNATS.wsb with the following XML code:

<Configuration>
  <VGpu>Default</VGpu>
  <Networking>Default</Networking>
  <MappedFolders>
    <MappedFolder>
      <HostFolder>C:\SandboxNATS</HostFolder>
      <SandboxFolder>C:\NATSFiles</SandboxFolder>
      <ReadOnly>false</ReadOnly>
    </MappedFolder>
  </MappedFolders>
  <LogonCommand>
    <Command>powershell.exe -ExecutionPolicy Bypass -NoExit -File C:\NATSFiles\Start-NATS.ps1</Command>
  </LogonCommand>
</Configuration>

Authoring NATS Startup Script

Inside the mapped host folder (C:\SandboxNATS), create the PowerShell initialization script named Start-NATS.ps1:

Write-Host "=============================================" -ForegroundColor Cyan
Write-Host " Starting NATS High-Performance Server...   " -ForegroundColor Green
Write-Host " Client Port:  127.0.0.1:4222                " -ForegroundColor Yellow
Write-Host " HTTP Monitor: http://127.0.0.1:8222         " -ForegroundColor Yellow
Write-Host "=============================================" -ForegroundColor Cyan

# Set working directory to mapped folder
Set-Location "C:\NATSFiles"

# Launch NATS server with JetStream enabled in memory
& "C:\NATSFiles\nats-server.exe" -p 4222 -m 8222 -js -sd "C:\NATSFiles\jetstream_data"

Running and Validating Messaging in the Sandbox

Double-click RunNATS.wsb on your Windows 11 host. Windows Sandbox boots up, mounts the mapped folder, and immediately launches NATS inside an interactive PowerShell window.

The server binds to port 4222 for client connections and port 8222 for HTTP monitoring. Open Microsoft Edge inside the sandbox and navigate to http://127.0.0.1:8222/varz to inspect active server metrics, connection counts, and memory allocations.

You can publish and subscribe to subjects, test JetStream deduplication windows, and verify consumer delivery semantics in complete isolation. When testing concludes, closing the sandbox window instantly eliminates all JetStream storage, consumer state, and server processes, leaving your host workstation completely clean.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.