Skip to content

Instantly share code, notes, and snippets.

@hasan-hasanov
Created November 25, 2020 23:25
Show Gist options
  • Select an option

  • Save hasan-hasanov/e8797aa4929f3394f5b1979df152175a to your computer and use it in GitHub Desktop.

Select an option

Save hasan-hasanov/e8797aa4929f3394f5b1979df152175a to your computer and use it in GitHub Desktop.
Sample code for medium article.
<Configuration>
<VGpu>Disabled</VGpu>
<Networking>Default</Networking>
<MappedFolders>
<MappedFolder>
<HostFolder>C:\Users\YOUR_USERNAME\Desktop\Scripts</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop\Sandbox\</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
</MappedFolders>
<LogonCommand>
<Command>powershell.exe -ExecutionPolicy Bypass -File C:\Users\WDAGUtilityAccount\Desktop\Sandbox\MainScript.ps1</Command>
</LogonCommand>
<AudioInput>Default</AudioInput>
<VideoInput>Default</VideoInput>
<ProtectedClient>Default</ProtectedClient>
<PrinterRedirection>Default</PrinterRedirection>
<ClipboardRedirection>Default</ClipboardRedirection>
<MemoryInMB>0</MemoryInMB>
</Configuration>
<Configuration>
<VGpu>Disable</VGpu>
<Networking>Disable</Networking>
<MappedFolders>
<!-- Basically this block copies Host folder a.k.a. C:\Users\Public\Downloads
To the desktop inside Windows Sandbox.
-->
<MappedFolder>
<!-- This is a path from the host machine. -->
<HostFolder>C:\Users\Public\Downloads</HostFolder>
<!-- This is the desktop inside the Windows Sandbox. -->
<SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop</SandboxFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
</MappedFolders>
<LogonCommand>
<Command>explorer.exe C:\users\WDAGUtilityAccount\Downloads</Command>
</LogonCommand>
</Configuration>
# Download and install Scoop Package manager
# Note: This will not work if you disable the network access from
# Windows Sandbox configuration file.
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
# Scoop package manager requires git to be able to install most software.
scoop install git
# Add extra buckets so we have more software to choose from.
scoop bucket add extras
scoop bucket add nerd-fonts
scoop bucket add nirsoft
scoop bucket add java
scoop bucket add jetbrains
scoop bucket add nonportable
scoop bucket add php
# Install Fiddler and Curl
scoop install fiddler, curl
ISandbox sandbox = new Sandbox();
await sandbox.Run(new List<IScript>()
{
new ExternalScript(new FileInfo(@"C:\Users\Scripts\StartBrowser.ps1"), new PowershellTranslator()),
new ExternalScript(new FileInfo(@"C:\Users\Scripts\StartExplorer.ps1"), new PowershellTranslator()),
});
ISandbox sandbox = new Sandbox();
await sandbox.Run(new List<IScript>()
{
// PowerShell script as string to open notepad
new LiteralScript(new List<string>() { @"Start-Process 'C:\windows\system32\notepad.exe'" }, new PowershellTranslator()),
// Cmd script to open a browser
new ExternalScript(new FileInfo(@"C:\Users\Scripts\StartBrowser.cmd"), new CmdTranslator()),
// Bat script to open explorer
new ExternalScript(new FileInfo(@"C:\Users\Scripts\OpenExplorer.bat"), new BatTranslator()),
// Scoop package manager that installs curl and fiddler
new ScoopPackageManagerScript(new List<string>(){ "curl", "fiddler" }),
});
IOptions options = new Options()
{
AudioInput = AudioInputOptions.Enable,
PrinterRedirection = PrinterRedirectionOptions.Enable,
Networking = NetworkingOptions.Default,
VGpu = VGpuOptions.Enabled,
// ...
};
ISandbox sandbox = new Sandbox(options);
ISandbox sandbox = new Sandbox();
await sandbox.Run(new ScoopPackageManagerScript(new List<string>() { "curl", "fiddler", "vscode" }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment