Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
# run-tests-in-sandbox.ps1 - host-side launcher with live log streaming
#
# Legacy Windows Sandbox runner.
#
# Usage (from libs/cua-driver):
# .\tests\runners\windows-sandbox\run-tests-in-sandbox.ps1 [<test-filter>]
#
# Steps:
# 1. cargo build + cargo test --no-run
# 2. Launch Windows Sandbox with workspace mapped read-only
# 3. Tail runner-log.txt and test-output.txt live (2s poll)
# 4. Exit with sandbox test exit code
param([string]$TestFilter = "")
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
function Close-Sandbox {
Write-Host "`n[SANDBOX] Closing sandbox..." -ForegroundColor Yellow
$names = @("WindowsSandboxClient", "WindowsSandbox")
foreach ($n in $names) {
$procs = Get-Process $n -ErrorAction SilentlyContinue
if ($procs) {
Write-Host " Stopping $n (pid $($procs.Id -join ','))..."
$procs | Stop-Process -Force -ErrorAction SilentlyContinue
}
}
Start-Sleep -Milliseconds 1500
$ErrorActionPreference = "Continue"
foreach ($n in $names) { & taskkill /F /IM "$n.exe" }
$ErrorActionPreference = "Stop"
Write-Host " Sandbox closed." -ForegroundColor Green
}
$runnerDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$runnersDir = Split-Path -Parent $runnerDir
$testsDir = Split-Path -Parent $runnersDir
$cuaDriverRoot = Split-Path -Parent $testsDir
$rustRoot = Join-Path $cuaDriverRoot "rust"
Write-Host "=== cua-driver Windows Sandbox Test Runner ===" -ForegroundColor Cyan
Write-Host "cua-driver root: $cuaDriverRoot"
Write-Host "Rust workspace : $rustRoot"
# -- Pre-flight: fail fast if a sandbox is already running --------------------
$running = Get-Process "WindowsSandboxClient","WindowsSandbox" -ErrorAction SilentlyContinue
if ($running) {
Write-Host "`n[ERROR] Windows Sandbox is already running (pid $($running.Id -join ','))." -ForegroundColor Red
Write-Host " Only one sandbox instance is allowed at a time." -ForegroundColor Red
Write-Host " Close it first, or run: Close-Sandbox" -ForegroundColor Yellow
Write-Host " Killing existing sandbox and retrying..." -ForegroundColor Yellow
Close-Sandbox
$running = Get-Process "WindowsSandboxClient","WindowsSandbox" -ErrorAction SilentlyContinue
if ($running) {
Write-Host "[ERROR] Could not kill existing sandbox. Aborting." -ForegroundColor Red
exit 1
}
Write-Host "[OK] Existing sandbox closed. Proceeding." -ForegroundColor Green
}
# -- 1. Build ------------------------------------------------------------------
Push-Location $rustRoot
try {
Write-Host "`n[BUILD] cargo build..." -ForegroundColor Yellow
cargo build -p cua-driver
if ($LASTEXITCODE -ne 0) { throw "cargo build failed" }
Write-Host "`n[BUILD] cargo test --no-run (protocol_handshake_test)..." -ForegroundColor Yellow
cargo test -p cua-driver --test protocol_handshake_test --no-run
if ($LASTEXITCODE -ne 0) { throw "cargo test --no-run (protocol_handshake_test) failed" }
Write-Host "`n[BUILD] cargo test --no-run (harness_wpf_test)..." -ForegroundColor Yellow
cargo test -p cua-driver-e2e --test harness_wpf_test --no-run
if ($LASTEXITCODE -ne 0) { throw "cargo test --no-run (harness_wpf_test) failed" }
Write-Host "`n[BUILD] cargo test --no-run (harness_winui3_test)..." -ForegroundColor Yellow
cargo test -p cua-driver-e2e --test harness_winui3_test --no-run
if ($LASTEXITCODE -ne 0) { throw "cargo test --no-run (harness_winui3_test) failed" }
Write-Host "`n[BUILD] cargo test --no-run (harness_web_test)..." -ForegroundColor Yellow
cargo test -p cua-driver-e2e --test harness_web_test --no-run
if ($LASTEXITCODE -ne 0) { throw "cargo test --no-run (harness_web_test) failed" }
Write-Host "`n[BUILD] cargo test --no-run (launch_windows_test)..." -ForegroundColor Yellow
cargo test -p cua-driver-e2e --test launch_windows_test --no-run
if ($LASTEXITCODE -ne 0) { throw "cargo test --no-run (launch_windows_test) failed" }
Write-Host "`n[BUILD] cargo test --no-run (agent_cursor_windows_test)..." -ForegroundColor Yellow
cargo test -p cua-driver-e2e --test agent_cursor_windows_test --no-run
if ($LASTEXITCODE -ne 0) { throw "cargo test --no-run (agent_cursor_windows_test) failed" }
} finally { Pop-Location }
# -- 1.5. Build the test fixtures if dependencies are on PATH ------------------
# The harness produces test-apps/harness-*/ which the sandbox
# runner picks up via the existing mapped-folder route. Skip silently if
# a dependency isn't available - the smoke tests degrade to "skipped" inside
# the sandbox rather than failing the whole run.
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
$harnessBuild = Join-Path $cuaDriverRoot "tests\fixtures\build\windows.ps1"
if (Test-Path $harnessBuild) {
Write-Host "`n[BUILD] test fixtures (dotnet publish)..." -ForegroundColor Yellow
# build.ps1 sets $ErrorActionPreference=Stop and throws on
# `dotnet publish` failure - wrap so the throw doesn't abort
# the whole sandbox runner before we can log the skip.
try {
& $harnessBuild
if ($LASTEXITCODE -ne 0) {
Write-Host "[WARN] test fixture build failed (exit $LASTEXITCODE) - harness tests will skip." -ForegroundColor Yellow
}
} catch {
Write-Host "[WARN] test fixture build errored: $($_.Exception.Message) - harness tests will skip." -ForegroundColor Yellow
}
} else {
Write-Host "`n[SKIP] tests/fixtures/build/windows.ps1 not found - harness tests will skip." -ForegroundColor Yellow
}
} else {
Write-Host "`n[SKIP] dotnet CLI not on PATH - test fixture build skipped, harness tests will degrade." -ForegroundColor Yellow
}
$protocolBin = Get-ChildItem "$rustRoot\target\debug\deps\protocol_handshake_test-*.exe" |
Sort-Object LastWriteTime -Descending | Select-Object -First 1
if (-not $protocolBin) { throw "protocol_handshake_test-*.exe not found" }
Write-Host "protocol_handshake_test: $($protocolBin.Name)"
# -- 2. Prepare shared output folder ------------------------------------------
$outputDir = "$env:TEMP\cua-sandbox-output"
New-Item -ItemType Directory -Force $outputDir | Out-Null
Get-ChildItem $outputDir -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
$TestFilter | Out-File "$outputDir\test-filter.txt" -Encoding utf8 -NoNewline
# -- 3. Generate .wsb and launch -----------------------------------------------
$wsbContent = @"
<Configuration>
<MappedFolders>
<MappedFolder>
<HostFolder>$cuaDriverRoot</HostFolder>
<SandboxFolder>C:\cua-driver</SandboxFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>$outputDir</HostFolder>
<SandboxFolder>C:\sandbox-output</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
</MappedFolders>
<LogonCommand>
<Command>powershell -ExecutionPolicy Bypass -NonInteractive -File C:\cua-driver\tests\runners\windows-sandbox\sandbox-runner.ps1</Command>
</LogonCommand>
</Configuration>
"@
$wsbPath = "$env:TEMP\cua-driver-test.wsb"
$wsbContent | Out-File $wsbPath -Encoding utf8
Write-Host "`n[SANDBOX] Launching Windows Sandbox..." -ForegroundColor Yellow
$preLaunchCheck = Get-Process "WindowsSandboxClient","WindowsSandbox" -ErrorAction SilentlyContinue
if ($preLaunchCheck) {
Write-Host "[ERROR] A sandbox appeared just before launch. Aborting." -ForegroundColor Red
exit 1
}
Start-Process $wsbPath
# -- 4. Stream logs live --------------------------------------------------------
Write-Host "[STREAM] Tailing logs (Ctrl-C to abort)..." -ForegroundColor Yellow
$doneFile = "$outputDir\done.txt"
$logFile = "$outputDir\runner-log.txt"
$outputFile = "$outputDir\test-output.txt"
$logPos = 0
$outPos = 0
$timeout = 600
$elapsed = 0
$pollInterval = 2
while ($elapsed -lt $timeout) {
if (Test-Path $logFile) {
$content = Get-Content $logFile -Raw -Encoding utf8 -ErrorAction SilentlyContinue
if ($content -and $content.Length -gt $logPos) {
$newText = $content.Substring($logPos)
$logPos = $content.Length
$newText.TrimEnd() -split "`n" | ForEach-Object { Write-Host "[sandbox] $_" -ForegroundColor DarkCyan }
}
}
if (Test-Path $outputFile) {
$content = Get-Content $outputFile -Raw -Encoding utf8 -ErrorAction SilentlyContinue
if ($content -and $content.Length -gt $outPos) {
$newText = $content.Substring($outPos)
$outPos = $content.Length
$newText.TrimEnd() -split "`n" | ForEach-Object { Write-Host " $_" }
}
}
if (Test-Path $doneFile) { break }
Start-Sleep -Seconds $pollInterval
$elapsed += $pollInterval
}
# Final drain
foreach ($f in @($logFile, $outputFile)) {
if (Test-Path $f) {
$content = Get-Content $f -Raw -Encoding utf8 -ErrorAction SilentlyContinue
$pos = if ($f -eq $logFile) { $logPos } else { $outPos }
if ($content -and $content.Length -gt $pos) {
$content.Substring($pos).TrimEnd() -split "`n" | ForEach-Object { Write-Host " $_" }
}
}
}
if (-not (Test-Path $doneFile)) {
Write-Host "`nTIMEOUT after ${elapsed}s." -ForegroundColor Red
Close-Sandbox
exit 1
}
$exitCode = 0
if (Test-Path "$outputDir\exit-code.txt") {
$exitCode = [int](Get-Content "$outputDir\exit-code.txt" -Raw).Trim()
}
Write-Host ""
if ($exitCode -eq 0) { Write-Host "PASSED (exit 0)" -ForegroundColor Green } else { Write-Host "FAILED (exit $exitCode)" -ForegroundColor Red }
Close-Sandbox
exit $exitCode