How to Configure Windows Sandbox Local Hasura GraphQL Engine via XML in Windows 11

Developing modern data APIs frequently involves connecting GraphQL query engines directly to relational databases to generate instant CRUD endpoints, role-based access control (RBAC) rules, and real-time subscriptions. Hasura GraphQL Engine is one of the industry’s leading tools for this purpose. However, setting up PostgreSQL instances, configuring environment credentials, and testing GraphQL mutations often litters the host development environment with lingering services, background daemons, and orphaned databases. Windows Sandbox in Windows 11 Pro and Enterprise provides an ideal solution: a clean, isolated, disposable virtual environment that boots in seconds.

By scripting Windows Sandbox with custom XML configuration files (.wsb) and automated PowerShell setup routines, developers can deploy Hasura GraphQL Engine alongside PostgreSQL inside an ephemeral container, test schemas thoroughly, and tear down the environment instantly.

Windows Sandbox Architecture and Component Isolation

Windows Sandbox operates as a lightweight, read-only system clone of your host operating system, running under Microsoft’s Hyper-V hypervisor. Changes made within the container never alter host registry settings, services, or filesystem directories. A .wsb configuration file orchestrates container provisioning using standard tags:

  • <Networking>: Set to Enable to permit external internet access for package installations.
  • <MappedFolders>: Maps a host directory into the container to supply bootstrap scripts and schema definition files.
  • <LogonCommand>: Automatically executes startup scripts upon sandbox desktop initialization.

Authoring the Hasura Automated Setup Script

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

# bootstrap-hasura.ps1 - Automated Hasura & PostgreSQL Setup for Windows Sandbox
$ErrorActionPreference = "Stop"

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

# Install Docker CLI / Container tools or standalone binaries via winget
Write-Host "Installing PostgreSQL portable tools..." -ForegroundColor Yellow
winget install PostgreSQL.PostgreSQL --silent --accept-package-agreements --accept-source-agreements

# Install Hasura CLI for schema automation
Write-Host "Installing Hasura CLI..." -ForegroundColor Yellow
Invoke-WebRequest -Uri "https://github.com/hasura/graphql-engine/releases/latest/download/cli-hasura-windows-amd64.exe" -OutFile "C:\Windows\System32\hasura.exe"

# Author Hasura metadata and project structure
$projectDir = "C:\HasuraProject"
New-Item -ItemType Directory -Path $projectDir -Force
Set-Location $projectDir

# Generate config.yaml for Hasura CLI
$configYaml = @"
version: 3
endpoint: http://localhost:8080
admin_secret: HasuraSecret123!
metadata_directory: metadata
"@
$configYaml | Out-File -FilePath "$projectDir\config.yaml" -Encoding utf8

Write-Host "Hasura CLI and environment configured successfully." -ForegroundColor Green
Write-Host "Ready to connect to PostgreSQL or test GraphQL schemas." -ForegroundColor Cyan

# Launch Edge with Hasura documentation for quick reference
Start-Sleep -Seconds 2
Start-Process "msedge.exe" -ArgumentList "https://hasura.io/docs"

Authoring the Windows Sandbox WSB File

In the same folder on your host machine, create the configuration file named HasuraSandbox.wsb:

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

Executing and Testing in Windows Sandbox

  1. Double-click HasuraSandbox.wsb from your Windows 11 host.
  2. The sandbox initializes, maps the setup folder, and executes the PowerShell bootstrap script automatically.
  3. PostgreSQL utilities and the Hasura CLI are downloaded and placed into system paths.
  4. You can test migrations, inspect metadata exports, and execute GraphQL queries against test endpoints without modifying your host system.
  5. When finished, close the Sandbox window; all container state is discarded immediately.

Automating Hasura setups via Windows Sandbox ensures clean, repeatable testing workflows for modern GraphQL API development on Windows 11.

Get the best tech tips delivered straight to your inbox.

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