How to Configure Windows Sandbox Port Forwarding and Host Mapping Using WSB Files

Windows Sandbox provides a lightweight, disposable desktop environment built on Windows hypervisor technology, ideal for safely testing untrusted executables, experimenting with build scripts, and validating web applications in isolation. When the sandbox closes, all installed software, temp files, and registry edits are permanently discarded. While the basic sandbox launches with default system settings, users can customise network access, mapped folders, and startup automations using XML-based Windows Sandbox configuration files (.wsb).

Understanding the Windows Sandbox Configuration Format (.wsb)

A .wsb file is a standard UTF-8 encoded XML document associated with the Windows Sandbox executable. When launched by double-clicking or invoking via the command line, Windows Sandbox parses the directives in the file and constructs the guest environment accordingly.

The primary elements supported by the configuration schema include:

  • <VGpu>: Controls virtualised GPU hardware acceleration (Enable, Disable, or Default).
  • <Networking>: Manages network adapter connectivity (Enable, Disable, or Default).
  • <MappedFolders>: Mounts host directories directly into the guest desktop, with support for read-only flags.
  • <LogonCommand>: Executes a command, batch script, or PowerShell routine immediately after the guest operating system finishes booting.
  • <MemoryInMB>: Constrains the maximum RAM allocated to the sandbox instance.

Configuring Host Folder Sharing with Read-Only Security

To safely provide scripts, installers, or project repositories to the sandbox without allowing malware to modify your host filesystem, map directories with the <ReadOnly> directive:

<Configuration>
  <VGpu>Enable</VGpu>
  <Networking>Enable</Networking>
  <MappedFolders>
    <MappedFolder>
      <HostFolder>C:\Dev\TestTools</HostFolder>
      <SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop\Tools</SandboxFolder>
      <ReadOnly>true</ReadOnly>
    </MappedFolder>
  </MappedFolders>
</Configuration>

Inside the sandbox, files appear directly on the desktop of the default sandbox user account (WDAGUtilityAccount). Any attempt by a sandboxed application to overwrite or delete files in that folder is rejected by the hypervisor layer.

Configuring Port Forwarding and Reverse Proxy Access

Windows Sandbox connects to the host network via an internal virtual switch (NAT), receiving an IP address typically in the range 172.x.x.x or 192.168.x.x. By default, inbound connections from the host to a web server or backend service running inside the sandbox are blocked unless port proxying is established.

You can automate port forwarding using Windows netsh portproxy commands initiated through a logon script:

  1. Create a bootstrap script named init-server.cmd in your mapped host directory (e.g. C:DevTestToolsinit-server.cmd):
    @echo off
    rem Open local sandbox firewall for incoming traffic on port 8080
    netsh advfirewall firewall add rule name="Allow 8080" dir=in action=allow protocol=TCP localport=8080
    
    rem Start your application or test web server inside the guest
    start "" "C:\Program Files\nodejs\node.exe" "C:\Users\WDAGUtilityAccount\Desktop\Tools\server.js"
  2. Reference this script inside your .wsb file using <LogonCommand>:
    <Configuration>
      <Networking>Enable</Networking>
      <MappedFolders>
        <MappedFolder>
          <HostFolder>C:\Dev\TestTools</HostFolder>
          <SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop\Tools</SandboxFolder>
          <ReadOnly>false</ReadOnly>
        </MappedFolder>
      </MappedFolders>
      <LogonCommand>
        <Command>C:\Users\WDAGUtilityAccount\Desktop\Tools\init-server.cmd</Command>
      </LogonCommand>
    </Configuration>
  3. To access the sandboxed service from your physical host machine, obtain the guest IP address by running ipconfig inside the sandbox, or use PowerShell on the host to route traffic:
    # On host machine: forward host port 8080 to sandbox guest IP
    netsh interface portproxy add v4tov4 listenport=8080 listenaddress=127.0.0.1 connectport=8080 connectaddress=172.28.16.2

Automating Multi-Scenario Environments via PowerShell

Developers can generate dynamic .wsb configuration files programmatically using PowerShell to spin up tailored sandbox configurations for regression testing:

$wsbContent = @"
<Configuration>
  <MemoryInMB>4096</MemoryInMB>
  <VGpu>Disable</VGpu>
  <Networking>Enable</Networking>
  <MappedFolders>
    <MappedFolder>
      <HostFolder>$HOMEProjectsAppTest</HostFolder>
      <SandboxFolder>C:UsersWDAGUtilityAccountDesktopAppTest</SandboxFolder>
      <ReadOnly>true</ReadOnly>
    </MappedFolder>
  </MappedFolders>
  <LogonCommand>
    <Command>powershell.exe -ExecutionPolicy Bypass -File C:UsersWDAGUtilityAccountDesktopAppTest
un-tests.ps1</Command>
  </LogonCommand>
</Configuration>
"@

$filePath = "$HOMEDesktopautomated-test.wsb"
Set-Content -Path $filePath -Value $wsbContent -Encoding UTF8
Start-Process $filePath

Security Considerations and Clean-Up

Always maintain strict isolation hygiene when working with sandboxes:

  • Never map sensitive host directories (such as C:Windows or root user profiles) with write permissions.
  • Ensure portproxy rules added to the host via netsh are deleted once testing concludes:
    netsh interface portproxy delete v4tov4 listenport=8080 listenaddress=127.0.0.1
  • Do not store long-term credentials or production tokens inside mapped folders accessible to untrusted sandboxed code.

Configuring custom WSB files enables development and security teams to build reproducible, isolated sandboxes that protect the host operating system while enabling comprehensive network testing.

Get the best tech tips delivered straight to your inbox.

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