A robust PowerShell-based system for creating isolated Windows Sandbox development environments with offline package management.
This project provides a robust, isolated development environment for PowerShell development and testing. It addresses several key challenges in PowerShell development:
-
Isolated Testing Environment
- Safe execution of untested scripts
- Prevention of system-wide changes during development
- Isolated package and module testing
- Protection of production environments
-
Standardized Development Setup
- Consistent PowerShell Preview environment
- Pre-configured testing frameworks (Pester)
- Integrated development tools
- Standardized module structure
-
Reproducible Environment
- Manifest-based configuration
- Offline package management
- Version-controlled dependencies
- Consistent across different machines
-
Development Best Practices
- Proper testing infrastructure
- Code organization standards
- Error handling patterns
- Logging and debugging capabilities
- π Isolated development environment using Windows Sandbox
- π¦ Offline-first package management
- βοΈ JSON-based configuration manifest
- π οΈ Automated tool installation (VSCode, PowerShell, Git)
- π Flexible path mappings and permissions
- π Structured initialization sequence
- π§ͺ Built-in testing support
- Windows 10/11 Pro or Enterprise with Windows Sandbox feature enabled
- PowerShell 7+ (recommended)
- Internet connection (for initial package downloads only)
-
Clone this repository
-
Run the setup script:
.\setup-sandbox.ps1
The sandbox environment can be started using either the full commandlet name or its alias:
# Using the full commandlet name
Start-DevSandbox
# Using the alias
devsb
The sandbox starter supports several configuration options:
# Basic usage (uses all defaults)
devsb
# Enable PowerShell profile loading (default: disabled)
devsb -UseProfile
# Specify execution policy (default: Bypass)
devsb -ExecutionPolicy RemoteSigned
# Show verbose output
devsb -Verbose
# Specify custom script path
devsb -ScriptPath "path/to/custom/setup-sandbox.ps1"
- Runs with
-NoProfile
(profiles disabled) - Uses
Bypass
execution policy - Looks for script in
$env:USERPROFILE\.pwsh\sandbox\setup-sandbox.ps1
Parameter | Default | Description |
---|---|---|
-UseProfile |
$false |
Enable PowerShell profile loading |
-ExecutionPolicy |
"Bypass" |
Set PowerShell execution policy (Bypass/RemoteSigned/AllSigned/Restricted) |
-ScriptPath |
User's sandbox path | Custom path to setup script |
-Verbose |
$false |
Enable detailed output logging |
The environment is configured through setup-manifest.json
, which controls:
- π₯οΈ Sandbox hardware settings (memory, vGPU)
- π Network configuration
- π Path mappings and permissions
- π§ Installation sequences
- β‘ Package configurations
{
"sandboxConfig": {
"memoryInMB": 8192,
"vGPU": "Enable",
"networking": "Enable"
},
"paths": {
"packages": {
"root": "C:\\Packages",
"vscode": { ... },
"powershell": { ... },
"git": { ... }
}
}
}
-
System Drive (C:) Mappings
- Use direct paths for system drive:
C:\Windows
This is a critical hook/initialiser - Always include a Windows test folder mapping for initialization
<MappedFolder> <HostFolder>C:\Windows</HostFolder> <SandboxFolder>C:\Test</SandboxFolder> <ReadOnly>true</ReadOnly> </MappedFolder>
- Use direct paths for system drive:
-
Non-System Drive Mappings
- Use UNC paths for all non-system drives:
\\localhost\D$\Path
- Example for D: drive mapping:
<MappedFolder> <HostFolder>\\localhost\D$\Env\PSProfile\DevCode</HostFolder> <SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop\DevCode</SandboxFolder> <ReadOnly>false</ReadOnly> </MappedFolder>
- Use UNC paths for all non-system drives:
-
Folder Mapping Order
- Keep Windows test folder as first mapping
- Order other mappings by importance/usage
- Use consistent SandboxFolder paths (preferably under Desktop)
The logon command sets up the initial PowerShell environment:
<LogonCommand>
<Command>powershell -NoProfile -ExecutionPolicy Bypass -Command "Set-Location C:\Users\WDAGUtilityAccount\Desktop\DevCode"</Command>
</LogonCommand>
-
Memory and GPU Settings
<MemoryInMB>8192</MemoryInMB> <vGPU>Enable</vGPU> <Networking>Enable</Networking>
-
Read/Write Permissions
- Set most mappings as read-only for security
- Only enable write access for development directories
-
Path Structure
- Use Desktop location for easy access
- Maintain consistent path structure across configurations
- Follow principle of least privilege for permissions
The sandbox environment can be installed either at the user level or system-wide, with three possible locations for user-level installation.
-
Default Location (Windows PowerShell default user modules)
Install-SandboxModule -Scope User -Location Default # Installs to: $HOME\Documents\PowerShell\<Version>\Modules\Start-DevSandbox # Example: PowerShell 7 -> \PowerShell\7\Modules\Start-DevSandbox
-
OneDrive Location (Synced modules)
Install-SandboxModule -Scope User -Location OneDrive # Automatically detects OneDrive location in this order: # 1. Custom path from PWSH_ONEDRIVE_PATH # 2. Business OneDrive location # 3. Personal OneDrive location # 4. Default OneDrive in user profile # 5. Fallback: D:\OneDrive\Documents
-
Development Location (Local development environment)
Install-SandboxModule -Scope User -Location Development # Default: C:\Users\<Username>\.pwsh\sandbox\Modules\Start-DevSandbox
-
System-Wide Installation (Requires Admin)
Start-Process pwsh -Verb RunAs Install-SandboxModule -Scope System # Installs to: $env:ProgramFiles\PowerShell\<Version>\Modules\Start-DevSandbox
You can customize various aspects of the installation using environment variables:
# Set custom OneDrive path
$env:PWSH_ONEDRIVE_PATH = "E:\OneDrive\Documents" # Custom OneDrive location
# Set custom development path
$env:PWSH_DEV_PATH = "D:\Code\PowerShell" # Custom development location
# Set custom project root
$env:PWSH_PROJECT_ROOT = "MyProjects\Sandbox" # Custom project directory
# Set custom Setup Script
$env:PWSH_SETUP_SCRIPT = "custom-sandbox-setup.ps1" # Custom setup script name
# Install to custom location
Install-SandboxModule -Scope User -Location OneDrive
These environment variables can be set:
- Temporarily in your current session
- Permanently in your PowerShell profile
- System-wide through Windows Environment Variables
.
βββ setup-sandbox.ps1 # Main setup script
βββ setup-manifest.json # Configuration manifest
βββ README.md # Documentation
βββ packages/ # Offline packages
βββ vscode/
βββ powershell/
βββ git/
The environment uses an offline-first approach:
- Packages are pre-downloaded to a local cache
- Installation occurs from local cache in sandbox
- Fallback to online sources if needed
- β Visual Studio Code + Extensions
- β PowerShell Preview
- β Git
- β PowerShell Modules
The sandbox environment respects Windows Sandbox user profiles:
ContainerAdministrator
: For elevated installationsContainerUser
: Default user profilePublic
: Shared resources
- π Isolated environment
- π Configurable read-only mappings
- π‘οΈ Execution policy controls
- π Minimal system modification
-
Package Installation Fails
- Verify packages in offline cache
- Check manifest paths
- Ensure admin privileges
-
Path Mapping Issues
- Verify paths in manifest
- Check read/write permissions
- Ensure host paths exist
- Fork the repository
- Create a feature branch
- Submit a pull request
MIT License - See LICENSE file for details