windows-development-sandbox 0.0.0-stage → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.sandbox-config.example.json +14 -0
- package/README.md +78 -2
- package/config.example.json +332 -0
- package/dist/api.d.ts +31 -0
- package/dist/api.js +30 -0
- package/dist/bin/agent-sandbox.d.ts +2 -0
- package/dist/bin/agent-sandbox.js +3 -0
- package/dist/bin/claude-host.d.ts +2 -0
- package/dist/bin/claude-host.js +5 -0
- package/dist/bin/claude-sbx.d.ts +2 -0
- package/dist/bin/claude-sbx.js +3 -0
- package/dist/bin/codex-sbx.d.ts +2 -0
- package/dist/bin/codex-sbx.js +3 -0
- package/dist/bin/gemini-sbx.d.ts +2 -0
- package/dist/bin/gemini-sbx.js +3 -0
- package/dist/bin/sandbox.d.ts +2 -0
- package/dist/bin/sandbox.js +4 -0
- package/dist/bin/sbx-hide.d.ts +2 -0
- package/dist/bin/sbx-hide.js +3 -0
- package/dist/bin/sbx-show.d.ts +2 -0
- package/dist/bin/sbx-show.js +3 -0
- package/dist/cli/args.d.ts +32 -0
- package/dist/cli/args.js +111 -0
- package/dist/cli/commands/accounts.d.ts +2 -0
- package/dist/cli/commands/accounts.js +52 -0
- package/dist/cli/commands/context.d.ts +21 -0
- package/dist/cli/commands/context.js +54 -0
- package/dist/cli/commands/data.d.ts +46 -0
- package/dist/cli/commands/data.js +249 -0
- package/dist/cli/commands/index.d.ts +8 -0
- package/dist/cli/commands/index.js +8 -0
- package/dist/cli/commands/launch.d.ts +5 -0
- package/dist/cli/commands/launch.js +152 -0
- package/dist/cli/commands/maintenance.d.ts +8 -0
- package/dist/cli/commands/maintenance.js +125 -0
- package/dist/cli/commands/repair.d.ts +59 -0
- package/dist/cli/commands/repair.js +332 -0
- package/dist/cli/commands/sessions.d.ts +11 -0
- package/dist/cli/commands/sessions.js +113 -0
- package/dist/cli/commands/setup.d.ts +45 -0
- package/dist/cli/commands/setup.js +152 -0
- package/dist/cli/index.d.ts +14 -0
- package/dist/cli/index.js +96 -0
- package/dist/cli/manifest.d.ts +95 -0
- package/dist/cli/manifest.js +87 -0
- package/dist/cli/menu.d.ts +22 -0
- package/dist/cli/menu.js +187 -0
- package/dist/cli/settings.d.ts +11 -0
- package/dist/cli/settings.js +156 -0
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.js +103 -0
- package/dist/core/detect-databases.d.ts +15 -0
- package/dist/core/detect-databases.js +147 -0
- package/dist/core/detect-pwsh.d.ts +18 -0
- package/dist/core/detect-pwsh.js +111 -0
- package/dist/core/detect-toolchains.d.ts +30 -0
- package/dist/core/detect-toolchains.js +58 -0
- package/dist/core/local-config.d.ts +12 -0
- package/dist/core/local-config.js +64 -0
- package/dist/core/schema.d.ts +604 -0
- package/dist/core/schema.js +264 -0
- package/dist/core/types.d.ts +162 -0
- package/dist/core/types.js +1 -0
- package/dist/core/util.d.ts +53 -0
- package/dist/core/util.js +145 -0
- package/dist/core/workspace.d.ts +23 -0
- package/dist/core/workspace.js +162 -0
- package/dist/guest/daemon.d.ts +1 -0
- package/dist/guest/daemon.js +186 -0
- package/dist/guest/db.d.ts +1 -0
- package/dist/guest/db.js +60 -0
- package/dist/guest/env.d.ts +49 -0
- package/dist/guest/env.js +99 -0
- package/dist/guest/gitguard.d.ts +7 -0
- package/dist/guest/gitguard.js +60 -0
- package/dist/guest/gitrules.d.ts +2 -0
- package/dist/guest/gitrules.js +11 -0
- package/dist/guest/guide.d.ts +12 -0
- package/dist/guest/guide.js +68 -0
- package/dist/guest/main.d.ts +1 -0
- package/dist/guest/main.js +120 -0
- package/dist/guest/ptyhost.d.ts +40 -0
- package/dist/guest/ptyhost.js +94 -0
- package/dist/guest/setup/agents.d.ts +8 -0
- package/dist/guest/setup/agents.js +73 -0
- package/dist/guest/setup/claude.d.ts +21 -0
- package/dist/guest/setup/claude.js +138 -0
- package/dist/guest/setup/environment.d.ts +6 -0
- package/dist/guest/setup/environment.js +65 -0
- package/dist/guest/setup/hooks.d.ts +1 -0
- package/dist/guest/setup/hooks.js +36 -0
- package/dist/guest/setup/network.d.ts +10 -0
- package/dist/guest/setup/network.js +99 -0
- package/dist/guest/setup/policy.d.ts +3 -0
- package/dist/guest/setup/policy.js +18 -0
- package/dist/guest/setup/user.d.ts +7 -0
- package/dist/guest/setup/user.js +47 -0
- package/dist/guest/toolchains/binstall.d.ts +7 -0
- package/dist/guest/toolchains/binstall.js +55 -0
- package/dist/guest/toolchains/catalogue.d.ts +51 -0
- package/dist/guest/toolchains/catalogue.js +31 -0
- package/dist/guest/toolchains/cli.d.ts +10 -0
- package/dist/guest/toolchains/cli.js +64 -0
- package/dist/guest/toolchains/common.d.ts +37 -0
- package/dist/guest/toolchains/common.js +124 -0
- package/dist/guest/toolchains/databases.d.ts +7 -0
- package/dist/guest/toolchains/databases.js +226 -0
- package/dist/guest/toolchains/git.d.ts +3 -0
- package/dist/guest/toolchains/git.js +112 -0
- package/dist/guest/toolchains/go.d.ts +3 -0
- package/dist/guest/toolchains/go.js +33 -0
- package/dist/guest/toolchains/index.d.ts +13 -0
- package/dist/guest/toolchains/index.js +122 -0
- package/dist/guest/toolchains/java.d.ts +8 -0
- package/dist/guest/toolchains/java.js +96 -0
- package/dist/guest/toolchains/managers.d.ts +16 -0
- package/dist/guest/toolchains/managers.js +82 -0
- package/dist/guest/toolchains/msvc.d.ts +10 -0
- package/dist/guest/toolchains/msvc.js +216 -0
- package/dist/guest/toolchains/native.d.ts +12 -0
- package/dist/guest/toolchains/native.js +220 -0
- package/dist/guest/toolchains/node.d.ts +3 -0
- package/dist/guest/toolchains/node.js +132 -0
- package/dist/guest/toolchains/pwsh.d.ts +4 -0
- package/dist/guest/toolchains/pwsh.js +14 -0
- package/dist/guest/toolchains/python.d.ts +3 -0
- package/dist/guest/toolchains/python.js +47 -0
- package/dist/guest/toolchains/runtimes.d.ts +17 -0
- package/dist/guest/toolchains/runtimes.js +40 -0
- package/dist/guest/toolchains/scripting.d.ts +10 -0
- package/dist/guest/toolchains/scripting.js +137 -0
- package/dist/guest/toolchains/versions.d.ts +47 -0
- package/dist/guest/toolchains/versions.js +77 -0
- package/dist/guest/toolchains/vscode.d.ts +2 -0
- package/dist/guest/toolchains/vscode.js +53 -0
- package/dist/guest/view.d.ts +1 -0
- package/dist/guest/view.js +22 -0
- package/dist/host/accounts.d.ts +32 -0
- package/dist/host/accounts.js +119 -0
- package/dist/host/channel.d.ts +37 -0
- package/dist/host/channel.js +180 -0
- package/dist/host/claude-profile.d.ts +15 -0
- package/dist/host/claude-profile.js +103 -0
- package/dist/host/cleanup.d.ts +23 -0
- package/dist/host/cleanup.js +66 -0
- package/dist/host/generate.d.ts +15 -0
- package/dist/host/generate.js +185 -0
- package/dist/host/personalize.d.ts +10 -0
- package/dist/host/personalize.js +97 -0
- package/dist/host/platform.d.ts +17 -0
- package/dist/host/platform.js +114 -0
- package/dist/host/project-scan.d.ts +23 -0
- package/dist/host/project-scan.js +173 -0
- package/dist/host/repo-guard.d.ts +23 -0
- package/dist/host/repo-guard.js +128 -0
- package/dist/host/secrets.d.ts +14 -0
- package/dist/host/secrets.js +133 -0
- package/dist/host/terminal.d.ts +32 -0
- package/dist/host/terminal.js +127 -0
- package/dist/host/window.d.ts +4 -0
- package/dist/host/window.js +68 -0
- package/dist/runtime/daemon.js +20291 -0
- package/dist/runtime/db.js +20423 -0
- package/dist/runtime/gitguard.js +84 -0
- package/dist/runtime/main.js +22398 -0
- package/dist/runtime/view.js +19966 -0
- package/dist/selftest/cli.test.d.ts +2 -0
- package/dist/selftest/cli.test.js +30 -0
- package/dist/selftest/config.test.d.ts +3 -0
- package/dist/selftest/config.test.js +74 -0
- package/dist/selftest/data.test.d.ts +2 -0
- package/dist/selftest/data.test.js +73 -0
- package/dist/selftest/detect.test.d.ts +2 -0
- package/dist/selftest/detect.test.js +42 -0
- package/dist/selftest/fixtures.d.ts +232 -0
- package/dist/selftest/fixtures.js +63 -0
- package/dist/selftest/guest.test.d.ts +3 -0
- package/dist/selftest/guest.test.js +61 -0
- package/dist/selftest/harness.d.ts +14 -0
- package/dist/selftest/harness.js +36 -0
- package/dist/selftest/helpers.test.d.ts +2 -0
- package/dist/selftest/helpers.test.js +125 -0
- package/dist/selftest/host.test.d.ts +2 -0
- package/dist/selftest/host.test.js +71 -0
- package/dist/selftest/index.d.ts +1 -0
- package/dist/selftest/index.js +56 -0
- package/dist/selftest/live.test.d.ts +7 -0
- package/dist/selftest/live.test.js +127 -0
- package/dist/selftest/mirror.test.d.ts +3 -0
- package/dist/selftest/mirror.test.js +74 -0
- package/dist/selftest/security.test.d.ts +3 -0
- package/dist/selftest/security.test.js +143 -0
- package/dist/selftest/setup.test.d.ts +2 -0
- package/dist/selftest/setup.test.js +23 -0
- package/dist/selftest/sync.test.d.ts +3 -0
- package/dist/selftest/sync.test.js +82 -0
- package/dist/shared/download.d.ts +58 -0
- package/dist/shared/download.js +200 -0
- package/dist/shared/guest-paths.d.ts +30 -0
- package/dist/shared/guest-paths.js +61 -0
- package/dist/shared/netrules.d.ts +18 -0
- package/dist/shared/netrules.js +98 -0
- package/dist/shared/paths.d.ts +9 -0
- package/dist/shared/paths.js +22 -0
- package/dist/shared/pty-client.d.ts +86 -0
- package/dist/shared/pty-client.js +227 -0
- package/dist/shared/rundir.d.ts +30 -0
- package/dist/shared/rundir.js +86 -0
- package/dist/shared/safe-remove.d.ts +10 -0
- package/dist/shared/safe-remove.js +55 -0
- package/dist/shared/schema.d.ts +84 -0
- package/dist/shared/schema.js +51 -0
- package/dist/shared/system.d.ts +15 -0
- package/dist/shared/system.js +19 -0
- package/dist/sync/claude-mem.d.ts +8 -0
- package/dist/sync/claude-mem.js +77 -0
- package/dist/sync/history.d.ts +30 -0
- package/dist/sync/history.js +129 -0
- package/dist/sync/watcher.d.ts +13 -0
- package/dist/sync/watcher.js +116 -0
- package/hooks/post-agent/README.txt +1 -0
- package/hooks/pre-provision/README.txt +1 -0
- package/package.json +91 -4
- package/sandbox/bootstrap.ps1 +258 -0
- package/sandbox/gitshim.cs +35 -0
- package/sandbox/logon.cmd +16 -0
- package/sandbox/ptyhost.cs +603 -0
- package/sandbox/trust.cmd +35 -0
- package/sandbox/vswhere.cs +83 -0
- package/schemas/config.schema.json +1062 -0
- package/schemas/sandbox-config.schema.json +952 -0
package/package.json
CHANGED
|
@@ -1,6 +1,93 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "windows-development-sandbox",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "A disposable Windows Sandbox for development, with or without an AI agent (Claude Code, Codex, Gemini, opencode, ...): the folder you run it from is the workspace, toolchains and databases for your project install themselves, and nothing else on your PC is reachable.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"os": [
|
|
8
|
+
"win32"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"sandbox": "dist/bin/sandbox.js",
|
|
15
|
+
"windows-development-sandbox": "dist/bin/sandbox.js",
|
|
16
|
+
"agent-sandbox": "dist/bin/agent-sandbox.js",
|
|
17
|
+
"claude-sbx": "dist/bin/claude-sbx.js",
|
|
18
|
+
"claude-sandbox": "dist/bin/claude-sbx.js",
|
|
19
|
+
"codex-sbx": "dist/bin/codex-sbx.js",
|
|
20
|
+
"codex-sandbox": "dist/bin/codex-sbx.js",
|
|
21
|
+
"gemini-sbx": "dist/bin/gemini-sbx.js",
|
|
22
|
+
"gemini-sandbox": "dist/bin/gemini-sbx.js",
|
|
23
|
+
"claude-host": "dist/bin/claude-host.js",
|
|
24
|
+
"sbx-show": "dist/bin/sbx-show.js",
|
|
25
|
+
"sbx-hide": "dist/bin/sbx-hide.js"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/api.d.ts",
|
|
30
|
+
"default": "./dist/api.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"sandbox",
|
|
36
|
+
"schemas",
|
|
37
|
+
"hooks",
|
|
38
|
+
"config.example.json",
|
|
39
|
+
".sandbox-config.example.json",
|
|
40
|
+
"README.md"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -p tsconfig.json && node scripts/bundle.mjs && node scripts/schemas.mjs",
|
|
44
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
45
|
+
"rebuild": "npm run clean && npm run build",
|
|
46
|
+
"test": "npm run build && node dist/bin/agent-sandbox.js self-test",
|
|
47
|
+
"prepare": "npm run build",
|
|
48
|
+
"prepack": "npm run rebuild",
|
|
49
|
+
"release:patch": "npm version patch && git push --follow-tags",
|
|
50
|
+
"release:minor": "npm version minor && git push --follow-tags",
|
|
51
|
+
"release:major": "npm version major && git push --follow-tags",
|
|
52
|
+
"install:global": "node scripts/install-global.mjs",
|
|
53
|
+
"publish:npm": "node scripts/publish-npm.mjs",
|
|
54
|
+
"doctor": "node dist/bin/agent-sandbox.js doctor"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"keywords": [
|
|
60
|
+
"claude",
|
|
61
|
+
"claude-code",
|
|
62
|
+
"windows-sandbox",
|
|
63
|
+
"sandbox",
|
|
64
|
+
"agent",
|
|
65
|
+
"codex",
|
|
66
|
+
"gemini",
|
|
67
|
+
"development",
|
|
68
|
+
"opencode",
|
|
69
|
+
"databases",
|
|
70
|
+
"dynamodb"
|
|
71
|
+
],
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"@inquirer/prompts": "^7.10.1",
|
|
74
|
+
"commander": "^14.0.3",
|
|
75
|
+
"jsonc-parser": "^3.3.1",
|
|
76
|
+
"lodash": "^4.18.1",
|
|
77
|
+
"zod": "^4.6.5"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@types/lodash": "^4.17.26",
|
|
81
|
+
"@types/node": "^22.0.0",
|
|
82
|
+
"esbuild": "^0.28.2",
|
|
83
|
+
"typescript": "^5.8.0"
|
|
84
|
+
},
|
|
85
|
+
"repository": {
|
|
86
|
+
"type": "git",
|
|
87
|
+
"url": "git+https://github.com/JoshDiDuca/agent-sandbox.git"
|
|
88
|
+
},
|
|
89
|
+
"homepage": "https://github.com/JoshDiDuca/agent-sandbox#readme",
|
|
90
|
+
"bugs": {
|
|
91
|
+
"url": "https://github.com/JoshDiDuca/agent-sandbox/issues"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
#Requires -Version 5.1
|
|
2
|
+
# Runs INSIDE Windows Sandbox (Windows PowerShell 5.1) in the sandbox window, started by logon.cmd.
|
|
3
|
+
# Its only job: make sure the runner's Node exists in persistent storage, then hand over to runtime\main.js.
|
|
4
|
+
# (That Node only runs agent-sandbox itself; the agent's `node` comes from nvm.)
|
|
5
|
+
$ErrorActionPreference = 'Stop'
|
|
6
|
+
$ProgressPreference = 'SilentlyContinue' # progress bars make PS 5.1 downloads extremely slow
|
|
7
|
+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
8
|
+
|
|
9
|
+
$launchDir = 'C:\AgentLaunch'
|
|
10
|
+
$dataDir = 'C:\AgentData'
|
|
11
|
+
$hostNodeDir = 'C:\HostTools\node'
|
|
12
|
+
$hostNvm = 'C:\HostTools\nvm'
|
|
13
|
+
$toolsDir = Join-Path $dataDir 'tools'
|
|
14
|
+
# The runner's Node lives with nvm's versions (tools\nvm\v<version>), so nvm reuses it instead of copying it again.
|
|
15
|
+
$nvmDir = Join-Path $toolsDir 'nvm'
|
|
16
|
+
$runnerFile = Join-Path $toolsDir 'runner-node.txt'
|
|
17
|
+
$nodeDir = $null
|
|
18
|
+
$nodeExe = $null
|
|
19
|
+
$logsDir = Join-Path $dataDir 'logs'
|
|
20
|
+
$runDir = Join-Path $dataDir 'run'
|
|
21
|
+
foreach ($dir in @($logsDir, $toolsDir, $nvmDir, $runDir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
|
|
22
|
+
$host.UI.RawUI.WindowTitle = 'Agent Sandbox'
|
|
23
|
+
Write-Host 'Agent sandbox bootstrap started.' -ForegroundColor Cyan
|
|
24
|
+
$transcript = Join-Path $logsDir ('bootstrap-' + (Get-Date -Format 'yyyyMMdd-HHmmss') + '.log')
|
|
25
|
+
Start-Transcript -Path $transcript | Out-Null
|
|
26
|
+
$transcriptStopped = $false
|
|
27
|
+
# -Encoding UTF8: Windows PowerShell 5.1 otherwise reads it in the ANSI code page (non-ASCII paths and names break).
|
|
28
|
+
$session = Get-Content -LiteralPath (Join-Path $launchDir 'session.json') -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
29
|
+
$hostVersion = [string]$session.hostTools.nodeVersion
|
|
30
|
+
|
|
31
|
+
function Set-Status([string]$Phase, [string]$Message) {
|
|
32
|
+
# Same shape as SandboxStatus in src/shared/schema.ts; written atomically so the host never reads half a file.
|
|
33
|
+
$status = [ordered]@{ launchId = $session.launchId; phase = $Phase; message = $Message; updatedAt = (Get-Date).ToUniversalTime().ToString('o'); workspaceHost = $session.workspaceHost; guestWorkspace = $session.workspace; headless = [bool]$session.headless }
|
|
34
|
+
$file = Join-Path $runDir 'sandbox.json'
|
|
35
|
+
[IO.File]::WriteAllText("$file.tmp", ($status | ConvertTo-Json -Compress))
|
|
36
|
+
Move-Item -LiteralPath "$file.tmp" -Destination $file -Force
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function Invoke-Download([string]$Uri, [string]$OutFile) {
|
|
40
|
+
# The sandbox network can take a few seconds to come up, so retry.
|
|
41
|
+
for ($attempt = 1; $attempt -le 5; $attempt++) {
|
|
42
|
+
try {
|
|
43
|
+
if ($OutFile) { Invoke-WebRequest -Uri $Uri -OutFile $OutFile -UseBasicParsing; return $null }
|
|
44
|
+
$response = Invoke-WebRequest -Uri $Uri -UseBasicParsing
|
|
45
|
+
if ($response.Content -is [byte[]]) { return [Text.Encoding]::UTF8.GetString($response.Content) }
|
|
46
|
+
return [string]$response.Content
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
if ($attempt -eq 5) { throw }
|
|
50
|
+
Write-Warning "Download failed (attempt $attempt of 5): $($_.Exception.Message). Retrying ..."
|
|
51
|
+
Start-Sleep -Seconds 4
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function Set-Runner([string]$Version) {
|
|
57
|
+
$script:nodeDir = Join-Path $nvmDir ('v' + $Version.TrimStart('v'))
|
|
58
|
+
$script:nodeExe = Join-Path $script:nodeDir 'node.exe'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function Test-Node {
|
|
62
|
+
if (-not (Test-Path -LiteralPath $nodeExe)) { return $false }
|
|
63
|
+
try { $null = & $nodeExe --version; return ($LASTEXITCODE -eq 0) } catch { return $false }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function Find-CachedRunner {
|
|
67
|
+
# This PC's version first (nvm will want it anyway), else whichever version the last boot used.
|
|
68
|
+
$last = if (Test-Path -LiteralPath $runnerFile) { (Get-Content -LiteralPath $runnerFile -Raw -Encoding UTF8).Trim() } else { '' }
|
|
69
|
+
foreach ($version in @($hostVersion, $last)) {
|
|
70
|
+
if ($version -notmatch '^\d+\.\d+\.\d+$') { continue }
|
|
71
|
+
Set-Runner $version
|
|
72
|
+
if (Test-Node) { return $true }
|
|
73
|
+
}
|
|
74
|
+
return $false
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function Publish-Directory([string]$Staging, [string]$Destination) {
|
|
78
|
+
if (Test-Path -LiteralPath $Destination) { Remove-Item -LiteralPath $Destination -Recurse -Force }
|
|
79
|
+
Move-Item -LiteralPath $Staging -Destination $Destination
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function Get-Size([string]$Path) {
|
|
83
|
+
if (-not (Test-Path -LiteralPath $Path)) { return 0 }
|
|
84
|
+
$sum = (Get-ChildItem -LiteralPath $Path -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
|
|
85
|
+
if ($null -eq $sum) { return 0 } else { return [long]$sum }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function Invoke-Robocopy([string]$Label, [string]$From, [string]$To, [string[]]$Options, [long]$Total) {
|
|
89
|
+
# Runs robocopy in the background and prints how far it has got, so a slow copy never looks frozen.
|
|
90
|
+
# /R:2 /W:1: robocopy's default is 1,000,000 retries 30 s apart, which hangs "forever" on one unreadable file.
|
|
91
|
+
$totalMb = [math]::Round($Total / 1MB, 1)
|
|
92
|
+
Write-Host " $Label ($totalMb MB) ..."
|
|
93
|
+
$argList = @("`"$From`"", "`"$To`"") + $Options + @('/XJ', '/R:2', '/W:1', '/NFL', '/NDL', '/NJH', '/NJS', '/NP')
|
|
94
|
+
$process = Start-Process -FilePath 'robocopy.exe' -ArgumentList $argList -NoNewWindow -PassThru
|
|
95
|
+
$null = $process.Handle # keeps ExitCode readable after the process exits
|
|
96
|
+
$started = Get-Date
|
|
97
|
+
while (-not $process.WaitForExit(2000)) {
|
|
98
|
+
$done = Get-Size $To
|
|
99
|
+
$pct = if ($Total -gt 0) { [math]::Min(100, [math]::Floor($done * 100 / $Total)) } else { 0 }
|
|
100
|
+
$secs = [int]((Get-Date) - $started).TotalSeconds
|
|
101
|
+
Write-Host (" {0}: {1} of {2} MB ({3}%), {4}s" -f $Label, [math]::Round($done / 1MB, 1), $totalMb, $pct, $secs)
|
|
102
|
+
}
|
|
103
|
+
$code = $process.ExitCode
|
|
104
|
+
if ($code -ge 8) { Write-Warning "robocopy failed copying $Label (exit code $code)"; return $false }
|
|
105
|
+
Write-Host (" {0}: done in {1}s" -f $Label, [int]((Get-Date) - $started).TotalSeconds)
|
|
106
|
+
return $true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function Copy-NodeFromHost {
|
|
110
|
+
# The host maps one of these: nvm (when this PC's Node is an nvm version) or the plain Node folder.
|
|
111
|
+
if ($hostVersion -notmatch '^\d+\.\d+\.\d+$') { return $false }
|
|
112
|
+
$hostNode = @((Join-Path $hostNvm "v$hostVersion"), $hostNodeDir) | Where-Object { Test-Path -LiteralPath (Join-Path $_ 'node.exe') } | Select-Object -First 1
|
|
113
|
+
if (-not $hostNode) { return $false }
|
|
114
|
+
# Only node.exe, the npm shims and node_modules\npm (same list as copyNode in src/guest/env.ts): nothing else is
|
|
115
|
+
# needed, and the folder can hold every global npm package, i.e. tens of thousands of small files over a slow mapping.
|
|
116
|
+
Write-Host "Copying Node $hostVersion from this PC ($hostNode) ..."
|
|
117
|
+
Set-Status 'booting' 'Copying Node from this PC'
|
|
118
|
+
$staging = Join-Path $toolsDir 'node-staging'
|
|
119
|
+
if (Test-Path -LiteralPath $staging) { Remove-Item -LiteralPath $staging -Recurse -Force }
|
|
120
|
+
$files = @('node.exe', 'npm', 'npm.cmd', 'npx', 'npx.cmd')
|
|
121
|
+
$filesSize = ($files | ForEach-Object { Get-Item -LiteralPath (Join-Path $hostNode $_) -ErrorAction SilentlyContinue } | Measure-Object -Property Length -Sum).Sum
|
|
122
|
+
$npmFrom = Join-Path $hostNode 'node_modules\npm'
|
|
123
|
+
$ok = (Invoke-Robocopy -Label 'node.exe' -From $hostNode -To $staging -Options ($files + '/J') -Total ([long]$filesSize)) -and
|
|
124
|
+
(Invoke-Robocopy -Label 'npm' -From $npmFrom -To (Join-Path $staging 'node_modules\npm') -Options @('/E', '/MT:16') -Total (Get-Size $npmFrom))
|
|
125
|
+
if (-not $ok) { return $false }
|
|
126
|
+
Set-Runner $hostVersion
|
|
127
|
+
Publish-Directory -Staging $staging -Destination $nodeDir
|
|
128
|
+
return (Test-Node)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function Mount-MirrorDrives {
|
|
132
|
+
# Windows Sandbox can only map folders onto C:, so a guest path like F:\Games\X is mapped to C:\Mirror\F\Games\X
|
|
133
|
+
# and F: is made here with subst (session.substDrives, written by the host; see src/shared/guest-paths.ts).
|
|
134
|
+
# subst drives belong to the logon session: everything started from here (main.js, the daemon, ptyhost, hooks,
|
|
135
|
+
# Windows Terminal tabs) and Explorer share it, because the sandbox user has one full token (UAC is off).
|
|
136
|
+
# Returns the letters that could NOT be mounted; an existing drive is reported, never replaced.
|
|
137
|
+
$subst = Join-Path $env:SystemRoot 'System32\subst.exe'
|
|
138
|
+
$failed = @()
|
|
139
|
+
foreach ($drive in @($session.substDrives)) {
|
|
140
|
+
if ($null -eq $drive) { continue }
|
|
141
|
+
$letter = ([string]$drive.letter).ToUpperInvariant()
|
|
142
|
+
$target = [string]$drive.target
|
|
143
|
+
if ($letter -notmatch '^[D-Z]$' -or $target -ne "C:\Mirror\$letter") { throw "Invalid subst drive in session.json: '$letter' -> '$target'." }
|
|
144
|
+
$existing = (& $subst) | ForEach-Object { if ($_ -match "^${letter}:\\: => (.+)$") { $Matches[1].Trim() } } | Select-Object -First 1
|
|
145
|
+
if ($existing -and $existing -eq $target) { Write-Host " ${letter}: already points to $target."; continue }
|
|
146
|
+
if ([IO.Directory]::GetLogicalDrives() | Where-Object { $_.Substring(0, 1).ToUpperInvariant() -eq $letter }) {
|
|
147
|
+
Write-Warning "Drive ${letter}: already exists in the sandbox, so it was left alone. Folders mapped to ${letter}:\... are at $target\... instead."
|
|
148
|
+
$failed += $letter
|
|
149
|
+
continue
|
|
150
|
+
}
|
|
151
|
+
if (-not (Test-Path -LiteralPath $target -PathType Container)) { New-Item -ItemType Directory -Path $target -Force | Out-Null }
|
|
152
|
+
# subst.exe exits 0 even when it fails, so check the drive itself.
|
|
153
|
+
& $subst "${letter}:" $target | Out-Host
|
|
154
|
+
if (Test-Path -LiteralPath "${letter}:\") { Write-Host " ${letter}: -> $target" }
|
|
155
|
+
else { Write-Warning "subst ${letter}: $target did not work. Folders mapped to ${letter}:\... are at $target\... instead."; $failed += $letter }
|
|
156
|
+
}
|
|
157
|
+
return ,$failed
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function Update-Environment {
|
|
161
|
+
# main.js writes PATH and the tool variables machine-wide; reload them so this (-NoExit) shell has nvm, git, etc.
|
|
162
|
+
foreach ($scope in @('Machine', 'User')) {
|
|
163
|
+
$vars = [Environment]::GetEnvironmentVariables($scope)
|
|
164
|
+
foreach ($name in $vars.Keys) { if ($name -ne 'Path') { Set-Item -LiteralPath "env:$name" -Value ([string]$vars[$name]) } }
|
|
165
|
+
}
|
|
166
|
+
$env:PATH = ([Environment]::GetEnvironmentVariable('Path', 'Machine'), [Environment]::GetEnvironmentVariable('Path', 'User') | Where-Object { $_ }) -join ';'
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function Install-NodeFromWeb {
|
|
170
|
+
$arch = if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { 'arm64' } else { 'x64' }
|
|
171
|
+
Write-Host 'Looking up the Node LTS release ...'
|
|
172
|
+
$index = (Invoke-Download -Uri 'https://nodejs.org/dist/index.json') | ConvertFrom-Json
|
|
173
|
+
$release = $index | Where-Object { $_.lts -and ($_.files -contains "win-$arch-zip") } | Select-Object -First 1
|
|
174
|
+
if ($null -eq $release) { throw "No Node LTS release found ($arch)." }
|
|
175
|
+
$version = [string]$release.version
|
|
176
|
+
if ($version -notmatch '^v\d+\.\d+\.\d+$') { throw "Unexpected Node version string: $version" }
|
|
177
|
+
$zipName = "node-$version-win-$arch.zip"
|
|
178
|
+
$baseUrl = "https://nodejs.org/dist/$version"
|
|
179
|
+
$work = Join-Path $toolsDir ('node-work-' + [guid]::NewGuid().ToString('N'))
|
|
180
|
+
New-Item -ItemType Directory -Path $work -Force | Out-Null
|
|
181
|
+
try {
|
|
182
|
+
$zipPath = Join-Path $work $zipName
|
|
183
|
+
Write-Host "Downloading $zipName ..."
|
|
184
|
+
$null = Invoke-Download -Uri "$baseUrl/$zipName" -OutFile $zipPath
|
|
185
|
+
$sums = Invoke-Download -Uri "$baseUrl/SHASUMS256.txt"
|
|
186
|
+
$line = ($sums -split "`n") | Where-Object { $_.Trim() -like "* $zipName" } | Select-Object -First 1
|
|
187
|
+
if (-not $line) { throw "No checksum entry for $zipName" }
|
|
188
|
+
$expected = ($line.Trim() -split '\s+')[0]
|
|
189
|
+
if ((Get-FileHash -LiteralPath $zipPath -Algorithm SHA256).Hash -ne $expected.ToUpper()) { throw 'Node download failed checksum verification.' }
|
|
190
|
+
$extractDir = Join-Path $work 'extracted'
|
|
191
|
+
New-Item -ItemType Directory -Path $extractDir -Force | Out-Null
|
|
192
|
+
& tar.exe -xf $zipPath -C $extractDir
|
|
193
|
+
if ($LASTEXITCODE -ne 0) { $global:LASTEXITCODE = 0; Expand-Archive -LiteralPath $zipPath -DestinationPath $extractDir -Force }
|
|
194
|
+
$inner = Join-Path $extractDir "node-$version-win-$arch"
|
|
195
|
+
if (-not (Test-Path -LiteralPath (Join-Path $inner 'node.exe'))) { throw 'Unexpected Node archive layout.' }
|
|
196
|
+
Set-Runner $version
|
|
197
|
+
Publish-Directory -Staging $inner -Destination $nodeDir
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
if (Test-Path -LiteralPath $work) { Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue }
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
# First: hooks, toolchains and the agent all run in (or below) the workspace, which may be on one of these drives.
|
|
206
|
+
$unmounted = Mount-MirrorDrives
|
|
207
|
+
$workspaceDrive = ([string]$session.workspace).Substring(0, 1).ToUpperInvariant()
|
|
208
|
+
if ($unmounted -contains $workspaceDrive) {
|
|
209
|
+
throw "The workspace $($session.workspace) needs drive ${workspaceDrive}:, which could not be created in the sandbox (see the warning above). Set guestWorkspace to ""auto"" (C:\Workspace\<name>) for this project."
|
|
210
|
+
}
|
|
211
|
+
Set-Status 'booting' 'Preparing the runner'
|
|
212
|
+
$provisioning = $session.provisioning
|
|
213
|
+
if (-not $provisioning.refresh -and (Find-CachedRunner)) {
|
|
214
|
+
Write-Host ('Runner Node ' + (& $nodeExe --version) + ' cached in persistent storage.')
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
$ready = $false
|
|
218
|
+
if ($provisioning.copyFromHost) {
|
|
219
|
+
$ready = Copy-NodeFromHost
|
|
220
|
+
if (-not $ready) {
|
|
221
|
+
if (-not $provisioning.fallbackToInstall) { throw 'Could not copy Node from this PC and provisioning.fallbackToInstall is false.' }
|
|
222
|
+
Write-Warning 'Host Node unavailable; downloading Node instead.'
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (-not $ready) { Install-NodeFromWeb }
|
|
226
|
+
if (-not (Test-Node)) { throw 'Node is not runnable after provisioning.' }
|
|
227
|
+
Write-Host ('Runner Node ' + (& $nodeExe --version) + ' ready.')
|
|
228
|
+
}
|
|
229
|
+
[IO.File]::WriteAllText($runnerFile, (Split-Path -Leaf $nodeDir).TrimStart('v'))
|
|
230
|
+
# Older versions kept a full copy of the host's Node folder here.
|
|
231
|
+
$legacy = Join-Path $toolsDir 'node'
|
|
232
|
+
if (Test-Path -LiteralPath $legacy) { Remove-Item -LiteralPath $legacy -Recurse -Force -ErrorAction SilentlyContinue }
|
|
233
|
+
|
|
234
|
+
$env:PATH = "$nodeDir;$env:PATH"
|
|
235
|
+
Set-Location -LiteralPath $session.workspace
|
|
236
|
+
Stop-Transcript | Out-Null
|
|
237
|
+
$transcriptStopped = $true
|
|
238
|
+
& $nodeExe (Join-Path $launchDir 'runtime\main.js')
|
|
239
|
+
$code = $LASTEXITCODE
|
|
240
|
+
if ($code -ne 0) {
|
|
241
|
+
# main.js reports its own failures; this catches it dying before it could (e.g. a broken Node).
|
|
242
|
+
$current = Get-Content -LiteralPath (Join-Path $runDir 'sandbox.json') -Raw -Encoding UTF8 -ErrorAction SilentlyContinue | ConvertFrom-Json -ErrorAction SilentlyContinue
|
|
243
|
+
if ($null -eq $current -or $current.phase -ne 'failed') { Set-Status 'failed' ("The sandbox runner stopped (exit code $code). See C:\AgentData\logs.") }
|
|
244
|
+
Write-Host "The sandbox runner stopped with exit code $code. Logs: $logsDir" -ForegroundColor Red
|
|
245
|
+
}
|
|
246
|
+
Update-Environment
|
|
247
|
+
Write-Host "This window stays open in $($session.workspace)."
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
$report = ($_ | Format-List * -Force | Out-String) + "`r`n" + $_.ScriptStackTrace
|
|
251
|
+
Set-Content -Path (Join-Path $logsDir 'bootstrap-error.txt') -Value $report -Encoding UTF8
|
|
252
|
+
try { Set-Status 'failed' ('Bootstrap failed: ' + $_.Exception.Message) } catch { }
|
|
253
|
+
Write-Host $report -ForegroundColor Red
|
|
254
|
+
Write-Host "Saved to $logsDir\bootstrap-error.txt" -ForegroundColor Yellow
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
if (-not $transcriptStopped) { try { Stop-Transcript | Out-Null } catch { } }
|
|
258
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// git.exe stand-in for provisioning.git.access = readonly | none. Programs that look up "git" on PATH (Claude Code,
|
|
2
|
+
// Node, shells) find this first; it forwards the exact command line to gitguard.js, which allows or refuses the call.
|
|
3
|
+
// Compiled inside the sandbox with the .NET Framework csc.exe (C# 5).
|
|
4
|
+
using System;
|
|
5
|
+
using System.Diagnostics;
|
|
6
|
+
|
|
7
|
+
static class GitShim
|
|
8
|
+
{
|
|
9
|
+
static int Main()
|
|
10
|
+
{
|
|
11
|
+
string node = Environment.GetEnvironmentVariable("AGENT_GUARD_NODE");
|
|
12
|
+
string guard = Environment.GetEnvironmentVariable("AGENT_GUARD_SCRIPT");
|
|
13
|
+
if (string.IsNullOrEmpty(node) || string.IsNullOrEmpty(guard))
|
|
14
|
+
{
|
|
15
|
+
Console.Error.WriteLine("fatal: git is not available in this sandbox.");
|
|
16
|
+
return 128;
|
|
17
|
+
}
|
|
18
|
+
var start = new ProcessStartInfo(node, "\"" + guard + "\" " + ArgumentsOf(Environment.CommandLine)) { UseShellExecute = false };
|
|
19
|
+
using (Process p = Process.Start(start))
|
|
20
|
+
{
|
|
21
|
+
p.WaitForExit();
|
|
22
|
+
return p.ExitCode;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Everything after the program name, untouched, so quoting survives exactly as the caller wrote it.
|
|
27
|
+
static string ArgumentsOf(string commandLine)
|
|
28
|
+
{
|
|
29
|
+
string s = commandLine.TrimStart();
|
|
30
|
+
int end;
|
|
31
|
+
if (s.StartsWith("\"")) { end = s.IndexOf('"', 1); end = end < 0 ? s.Length : end + 1; }
|
|
32
|
+
else { end = s.IndexOf(' '); if (end < 0) end = s.Length; }
|
|
33
|
+
return s.Substring(end).TrimStart();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
rem Windows Sandbox runs LogonCommand in a hidden window, so this opens the VISIBLE sandbox window: Windows Terminal
|
|
3
|
+
rem (downloaded once by the host into persistent storage), or a plain PowerShell window if it is missing or fails.
|
|
4
|
+
if not exist C:\AgentData\logs mkdir C:\AgentData\logs
|
|
5
|
+
echo logon.cmd ran at %date% %time% > C:\AgentData\logs\logon-hit.txt
|
|
6
|
+
call C:\AgentLaunch\sandbox\trust.cmd
|
|
7
|
+
set "PS=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe"
|
|
8
|
+
set "BOOT=%PS% -NoLogo -NoProfile -ExecutionPolicy Bypass -NoExit -File C:\AgentLaunch\sandbox\bootstrap.ps1"
|
|
9
|
+
if not exist C:\AgentData\tools\terminal\wt.exe goto plain
|
|
10
|
+
start "" C:\AgentData\tools\terminal\wt.exe --maximized new-tab --title "Agent Sandbox" -d C:\AgentLaunch %BOOT%
|
|
11
|
+
rem If Windows Terminal could not start, fall back to PowerShell so there is always a window.
|
|
12
|
+
%SystemRoot%\System32\timeout.exe /t 10 /nobreak >nul
|
|
13
|
+
%SystemRoot%\System32\tasklist.exe /fi "imagename eq WindowsTerminal.exe" | %SystemRoot%\System32\find.exe /i "WindowsTerminal" >nul && exit /b 0
|
|
14
|
+
echo Windows Terminal did not start; using PowerShell. >> C:\AgentData\logs\logon-hit.txt
|
|
15
|
+
:plain
|
|
16
|
+
start "Agent Sandbox" %BOOT%
|