How to Configure Windows Sandbox Local Caddy Reverse Proxy via XML in Windows 11

Modern web infrastructure increasingly adopts Caddy as a lightweight, memory-safe reverse proxy and web server thanks to its native automatic HTTPS, straightforward configuration syntax (Caddyfile), and modular plugin architecture. When testing microservice reverse proxies, header rewrites, or API gateway configurations, developers often want to validate routing rules locally before committing them to production. Installing Caddy as a host service or running local root CA trust modifications can complicate your main workstation setup. Windows Sandbox in Windows 11 Pro and Enterprise provides an ephemeral, hardware-isolated guest instance ideal for disposable Caddy reverse proxy testing.

By pairing automated Windows Sandbox configuration files (.wsb) with PowerShell setup scripts, developers can spin up an ephemeral Caddy testing sandbox with a single double-click, test routing behavior thoroughly, and discard the environment cleanly upon exit.

Windows Sandbox Architecture and Networking Setup

Windows Sandbox runs a lightweight, pristine guest instance based on your host operating system build, powered by Microsoft’s Hyper-V hypervisor. A .wsb XML configuration file controls its startup parameters:

  • <Networking>: Must be Enable to permit external internet access to download Caddy binaries via winget.
  • <MappedFolders>: Maps a host directory into the container to pass bootstrap scripts, custom Caddyfile configurations, and static HTML test assets.
  • <LogonCommand>: Automatically executes PowerShell bootstrap routines when the sandbox desktop loads.

Creating the Caddy Setup Script

Create a directory on your host machine (e.g., C:\Sandbox\Caddy) and save the following script as bootstrap-caddy.ps1:

# bootstrap-caddy.ps1 - Automated Caddy Setup for Windows Sandbox
$ErrorActionPreference = "Stop"

Write-Host "Configuring Caddy Sandbox Environment..." -ForegroundColor Cyan

# Install Caddy via winget
Write-Host "Installing Caddy web server..." -ForegroundColor Yellow
winget install CaddyServer.Caddy --silent --accept-package-agreements --accept-source-agreements

# Define Caddy working directory
$caddyDir = "C:\CaddyApp"
New-Item -ItemType Directory -Path "$caddyDir\html" -Force
Set-Location $caddyDir

# Author mock static webpage
@"
<!DOCTYPE html>
<html>
<head><title>Windows Sandbox Caddy Test</title></head>
<body style='font-family: sans-serif; text-align: center; padding: 50px;'>
    <h1>Caddy Web Server is Active!</h1>
    <p>Running securely inside an isolated Windows Sandbox instance.</p>
</body>
</html>
"@ | Out-File -FilePath "$caddyDir\html\index.html" -Encoding utf8

# Author Caddyfile configuration
$caddyfile = @"
:8080 {
    root * C:/CaddyApp/html
    file_server

    handle /api/* {
        respond "{"service":"caddy","status":"operational"}" 200
    }
}
"@
$caddyfile | Out-File -FilePath "$caddyDir\Caddyfile" -Encoding utf8

# Launch Caddy in background
Write-Host "Starting Caddy server on port 8080..." -ForegroundColor Green
Start-Process "caddy.exe" -ArgumentList "run --config C:/CaddyApp/Caddyfile" -WorkingDirectory $caddyDir

# Open Edge to verify endpoint
Start-Sleep -Seconds 3
Start-Process "msedge.exe" -ArgumentList "http://localhost:8080"

Authoring the Windows Sandbox WSB File

In the same folder, create the configuration file named CaddySandbox.wsb:

<Configuration>
  <VGpu>Enable</VGpu>
  <Networking>Enable</Networking>
  <MappedFolders>
    <MappedFolder>
      <HostFolder>C:\Sandbox\Caddy</HostFolder>
      <SandboxFolder>C:\CaddySetup</SandboxFolder>
      <ReadOnly>true</ReadOnly>
    </MappedFolder>
  </MappedFolders>
  <LogonCommand>
    <Command>powershell.exe -ExecutionPolicy Bypass -NoExit -File C:\CaddySetup\bootstrap-caddy.ps1</Command>
  </LogonCommand>
</Configuration>

Running and Testing Caddy in Windows Sandbox

  1. Double-click CaddySandbox.wsb on your Windows 11 host.
  2. Windows Sandbox initializes, maps the configuration folder, and executes the PowerShell setup script.
  3. Caddy is installed silently, configured with the Caddyfile, and started on port 8080.
  4. Microsoft Edge launches automatically displaying the active test page and JSON endpoint.
  5. When finished, close the Sandbox window; all temporary server files, logs, and processes are instantly purged.

This automated approach provides an efficient, clean environment for testing Caddy reverse proxy configurations on Windows 11 without impacting your host development system.

Get the best tech tips delivered straight to your inbox.

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