How to Configure Windows Sandbox Local WireMock Mock Server via XML in Windows 11

During microservice development, contract testing, and front-end integration testing, applications frequently rely on external REST API endpoints, payment gateways, or OAuth identity providers. Running integration test suites against live third-party cloud environments can be slow, costly, and unreliable due to rate limits or intermittent network failures. WireMock provides a flexible HTTP mock server that stubs responses and simulates faults. By mounting WireMock into Windows Sandbox via a .wsb XML file, developers can spin up an ephemeral API mocking server in seconds without modifying host Java runtimes. This tutorial covers the complete configuration.

The Architecture of Ephemeral Mock Testing

Windows Sandbox provides an isolated Hyper-V guest environment that communicates with the host over virtual NAT. By mapping a host directory containing the standalone WireMock JAR binary, test JSON stub mappings, and an automated PowerShell provisioning script via <MappedFolders>, the sandbox boots, installs a portable Java runtime silently, and binds WireMock to port 8080 immediately upon launch.

Structuring Host Folders and Assets

Create a dedicated automation directory on your Windows 11 host (for example, C:\SandboxWireMock):

C:\SandboxWireMock\
├── wiremock-standalone.jar
├── mappings\
│   └── test-api.json
├── Start-WireMock.ps1
└── WireMock_Sandbox.wsb

Authoring the Test Stub Mapping

Save a sample mock API definition as C:\SandboxWireMock\mappings\test-api.json:

{
  "request": {
    "method": "GET",
    "url": "/api/v1/customer/100"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "jsonBody": {
      "customerId": 100,
      "status": "Active",
      "tier": "Enterprise",
      "currency": "GBP"
    }
  }
}

Authoring the WireMock Provisioning Script

Save the following PowerShell script as C:\SandboxWireMock\Start-WireMock.ps1. This script launches the mock server and opens a test browser window:

# Start-WireMock.ps1 - Automated WireMock Launcher
param (
    [string]$JarPath = "C:\SandboxAssets\wiremock-standalone.jar",
    [string]$RootDir = "C:\SandboxAssets"
)

Write-Host "Initialising WireMock API Mock Server inside Windows Sandbox..." -ForegroundColor Cyan

# 1. Check for Java runtime or download portable OpenJDK
if (-not (Get-Command "java" -ErrorAction SilentlyContinue)) {
    Write-Host "Installing OpenJDK runtime via winget..." -ForegroundColor Yellow
    winget install --id Microsoft.OpenJDK.17 --exact --silent --accept-package-agreements --accept-source-agreements
    $env:PATH = "C:\Program Files\Microsoft\jdk-17.0.12.7-hotspot\bin;" + $env:PATH
}

# 2. Launch WireMock standalone
$WireMockProcess = Start-Process "java" -ArgumentList "-jar", $JarPath, "--port", "8080", "--root-dir", $RootDir, "--verbose" -PassThru -NoNewWindow

Write-Host "WireMock listening at http://localhost:8080" -ForegroundColor Green

# 3. Test endpoint via Edge
Start-Sleep -Seconds 3
Start-Process "msedge.exe" "http://localhost:8080/api/v1/customer/100"

# Keep session active
Wait-Process -Id $WireMockProcess.Id

Creating the WSB XML Configuration

Create WireMock_Sandbox.wsb with mapped folder access and automated script execution:

<Configuration>
  <VGpu>Enable</VGpu>
  <Networking>Default</Networking>
  <MappedFolders>
    <MappedFolder>
      <HostFolder>C:\SandboxWireMock</HostFolder>
      <SandboxFolder>C:\SandboxAssets</SandboxFolder>
      <ReadOnly>true</ReadOnly>
    </MappedFolder>
  </MappedFolders>
  <LogonCommand>
    <Command>powershell.exe -ExecutionPolicy Bypass -NoExit -File C:\SandboxAssets\Start-WireMock.ps1</Command>
  </LogonCommand>
</Configuration>

Executing and Auditing Mock API Services

  1. Double-click WireMock_Sandbox.wsb on your Windows 11 host.
  2. Windows Sandbox spins up in seconds, mounts the host directory, and executes PowerShell.
  3. WireMock starts on port 8080 and loads all JSON mappings from the mappings/ folder.
  4. Microsoft Edge launches automatically, displaying the JSON response: {"customerId":100,"status":"Active",...}.
  5. Execute test suites against the sandbox endpoint. When complete, closing the sandbox terminates all servers, leaving the host pristine.

Get the best tech tips delivered straight to your inbox.

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