Skip to content

Instantly share code, notes, and snippets.

@Beej126
Last active May 13, 2024 21:46
Show Gist options
  • Save Beej126/5b29720ff77bb1967a592024b3ca8d8d to your computer and use it in GitHub Desktop.
Save Beej126/5b29720ff77bb1967a592024b3ca8d8d to your computer and use it in GitHub Desktop.
Windows Sandbox Slipstreamed with Winget
*.appx
*.msixbundle
*.wsb

WinGet Slipstreamed into Windows Sandbox

I've just automated a few things on top of this original work: https://www.aloneguid.uk/posts/2022/12/launch-windows-sandbox-with-winget-enabled/

  1. downloading the winget install packages if not already present (this folder then gets shared into the guest sandbox)
    • dodges github's 100MB max file size limitation since the msixbundle is 250MB
  2. building a parameterized .wsb Sandbox Config file to avoid hard coding abolute paths which would make this whole bundle less portable
  3. prompting for & installing common tools inside the sandbox (e.g. vscode, git for windows)
  4. also sharing the hosts Downloads folder inside the sandbox for file transfer convenience

Files and their involvement

File Description
host_driver.ps1 this is the main script to be launched
sandbox_side.ps1 this gets called from inside the sandbox upon startup, to install winget, etc
appx & msix install packages for the winget binaries
find latest updates here: https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget-on-windows-sandbox

Sandbox Config file docs

https://learn.microsoft.com/en-us/windows/security/application-security/application-isolation/windows-sandbox/windows-sandbox-configure-using-wsb-file

#from: https://www.aloneguid.uk/posts/2022/12/launch-windows-sandbox-with-winget-enabled/
$desktopFolderName = $(Split-Path $pwd -Leaf)
@"
<Configuration>
<MappedFolders>
<MappedFolder>
<HostFolder>$env:USERPROFILE/Downloads</HostFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>$pwd</HostFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
</MappedFolders>
<LogonCommand>
<!-- need to spawn an additional powershell to provide a visible output window -->
<Command>cmd /c start powershell -executionpolicy unrestricted -noexit -file "%USERPROFILE%/Desktop/$desktopFolderName/sandbox_side.ps1" -desktopFolderName "$desktopFolderName"</Command>
</LogonCommand>
</Configuration>
"@ | Out-File -FilePath "$pwd\customized_sandbox_config.wsb"
Write-host "Downloading WinGet & dependency installs..."
if (!(Test-Path ./Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle)) { Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle }
if (!(Test-Path ./Microsoft.VCLibs.x64.14.00.Desktop.appx)) { Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx }
if (!(Test-Path ./Microsoft.UI.Xaml.2.8.x64.appx)) { Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx -OutFile Microsoft.UI.Xaml.2.8.x64.appx }
start customized_sandbox_config.wsb
[InternetShortcut]
URL=https://www.aloneguid.uk/posts/2022/12/launch-windows-sandbox-with-winget-enabled/
# from: https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget-on-windows-sandbox
param (
[string]$desktopFolderName
)
Write-host "Installing WinGet & dependencies..."
Add-AppxPackage -verbose ~/Desktop/$desktopFolderName/Microsoft.VCLibs.x64.14.00.Desktop.appx
Add-AppxPackage -verbose ~/Desktop/$desktopFolderName/Microsoft.UI.Xaml.2.8.x64.appx
Add-AppxPackage -verbose ~/Desktop/$desktopFolderName/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
function askMe([string] $ask, [ScriptBlock] $command) {
$Host.UI.RawUI.FlushInputBuffer()
$ask
if ($Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').Character -eq "y") { & $command }
}
askMe "install VSCode? (y/n)" { winget install -e --id Microsoft.VisualStudioCode -i }
askMe "install Git? (y/n)" { winget install -e --id Git.Git -i }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment