Skip to content

Commit

Permalink
Improve Sandbox configuration file and add README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
denelon committed Feb 17, 2024
1 parent 1825d04 commit 026e822
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Microsoft.WindowsSandbox
The [Microsoft.WindowsSandbox.DSC](https://www.powershellgallery.com/packages/Microsoft.WindowsSandbox.DSC) PowerShell module contains the WindowsSandbox DSC Resource. This resource accepts either a reference to a Windows Sandbox .WSB file or properties to configure and launch an instance of the Windows Sandbox.

>Note: The Windows Sandbox is an ephemoral instance of Windows. It also defaults to an administrative context when running the LogonCommand.
Prior to running this configuration, users should be on either Windows PRO or Windows enterprise. The "Windows Sandbox" optional feature also needs to be enabled.

The "full.sandbox.dsc.yaml" configuration is not fully capable of verifying the Windows SKU or enabling Windows optional features via the WinGet CLI (and subsequently Dev Home). The Windows optional features can be enabled in a configuration when run via the Microsoft.WinGet.Configuration.

The "full.sandbox.dsc.yaml" configuration can be run via the Microsoft.WinGet.Configuration module.

Install the module using:
```PowerShell
Install-Module -Name Microsoft.WindowsSandbox.DSC -AllowPrerelease
```

Run the configuration in PowerShell 7 using:
```PowerShell
get-WinGetConfiguration -File full.sandbox.dsc.yaml | Invoke-WinGetConfiguration
```

## How to use the WinGet Configuration File
The following two options are available for running a WinGet Configuration file on your device.

### 1. Windows Package Manager
1. Download the `sandbox.dsc.yaml` file to your computer.
1. Open your Windows Start Menu, search and launch "*Windows Terminal*".
1. Type the following: `CD <C:\Users\User\Download>`
1. Type the following: `winget configure --file .\sandbox.dsc.yaml`

### 2. Dev Home
1. Download the `sandbox.dsc.yaml` file to your computer.
1. Open your Windows Start Menu, search and launch "*Dev Home*".
1. Select the *Machine Configuration* button on the left side navigation.
1. Select the *Configuration file* button
1. Locate and open the WinGet Configuration file downloaded in "step 1".
1. Select the "I agree and want to continue" checkbox.
1. Select the "Set up as admin" button.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2

###############################################################################
# Create Windows Sandbox instance with WinGet installed. #
# Run as Administrator using Invoke-WinGetConfiguration #
# The Logon command performs the following steps in Windows PowerShell: #
# 1. Install Nuget package provider #
# 2. Install Microsoft.WinGet.Client (0.2.1) PS module from the PS gallery. #
# 3. Set the execution policy to RemoteSigned #
# 4. Run Repair-WingetPackageManager to install App Installer (WinGet). #
# Note: Modifying the C:\Sandbox directory contents in Windows Sanbox #
# will also modify C:\Sandbox on the Host filesystem. #
###############################################################################

properties:
resources:
- resource: PSDscResources/WindowsOptionalFeature
id: WindowsSandbox
directives:
description: Ensure Windows Sandbox is enabled
settings:
Name: Containers-DisposableClientVM
Ensure: Present
- resource: Microsoft.WindowsSandbox.DSC/WindowsSandbox
dependsOn:
- WindowsSandbox
directives:
description: Create Windows Sandbox with Winget installed
allowPrerelease: true
settings:
Ensure: Present
HostFolder: C:\Sandbox
SandboxFolder: C:\Sandbox
LogonCommand: >
cmd /c start powershell -NoExit -Command "Write-Host 'Installing NuGet package provider...';
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force;
Write-Host `n'Installing Microsoft.WinGet.Client PowerShell module...' `n;
Install-Module Microsoft.WinGet.Client -RequiredVersion 0.2.1 -Repository PSGallery -Force;
Write-Host 'Setting execution policy to remote signed...' `n;
Set-ExecutionPolicy RemoteSigned -Force;
Write-Host 'Running the Repair-WinGetPackageManager cmdlet to install App Installer (WinGet)...' `n;
Repair-WingetPackageManager
configurationVersion: 0.2.0

0 comments on commit 026e822

Please sign in to comment.