Hyper-V – Use VM as Sandbox


Windows Sandbox is a nice, but still relatively new feature in Windows 10. It is practical for testing various software, malware and so on in an isolated environment. But when a sandbox is closed, everything inside it is deleted. The next time it is started, it starts over from scratch. For those interested, I have written a story about how to customize a Windows Sandbox: Windows Sandbox – How to configure.

The Sandbox has some limitations. Customization options are limited to those explained in the preceding (linked) article. In addition, the Windows Sandbox cannot be restarted, therefore testing anything that needs a restart is impossible. Also, there’s no way to save its state.

A good alternative is to set up a Hyper-V virtual machine so that it does what Windows Sandbox does. As an added bonus you can restart your Sandbox VM, you can customize it as you like, you can save its state, and finally, you can reset it in a minute to restore its original, virgin state.

Create Sandbox VM

To start with, create a new VM. I recommend using the following settings:

- Generation 2 VM
- Secure boot enabled
- 4 virtual CPU
- 4 GB (4096 MB) virtual RAM
- Production Checkpoints
- Disable automatic Checkpoints
- Virtual NIC: Default Switch

Here’s the settings page from my Windows Sandbox VM:

Click to open enlarged in a new tab.

Using the Default Switch as a virtual NIC puts the virtual machine behind NAT (Network Address Translation). This, and not using Hyper-V Enhanced Mode, quite effectively isolates the VM from the host and its network.

First boot

Boot the VM from the Windows 10 install media, installing your preferred Windows 10 version and edition. Set up Windows using a local account: using a Microsoft account kind of invalidates the whole idea of a Sandbox.

When you visit the desktop for the first time, before doing anything else, create an initial checkpoint and label it clearly:

How to use a Sandbox VM

Your Sandbox VM is ready, completely isolated from the host and its network. You can use it for any kind of testing, even for some risky scenarios. You can shut down, restart and customize it as you wish. To reset your Sandbox VM, simply apply your initial checkpoint:

If you want to, you can create two desktop shortcuts: one to resume your Sandbox VM as it was the last time you shut it down, and one to reset it. I have written earlier about how to create Hyper-V shortcuts: Hyper-V Create shortcut for virtual machine

Create two PowerShell scripts to be used for those shortcuts. In the following examples, the VM name is W10 Sandbox, and the initial checkpoint name is Reset Sandbox. Here’s the first script / shortcut, to resume the Sandbox VM to its most recent saved state:

Start-VM "W10 Sandbox"
C:\Windows\System32\vmconnect.exe localhost "W10 Sandbox" | Out-Null
Stop-VM "W10 Sandbox"

And here’s a second one, to reset the Sandbox VM and start over from scratch:

Restore-VMCheckpoint -Name "Reset Sandbox" -VMName "W10 Sandbox" -Confirm:$false | Out-Null
Start-VM "W10 Sandbox"
C:\Windows\System32\vmconnect.exe localhost "W10 Sandbox" | Out-Null
Stop-VM "W10 Sandbox"

Now you can simply resume or reset your Sandbox VM by clicking the respective shortcut on your desktop.

That’s it. You will now have a flexible Windows Sandbox environment, completely isolated from your host device and network. Enjoy!

Kari

Author: Kari Finn

A former Windows Insider MVP, Kari started in computing in the mid 80’s writing code for VAX / VMS systems. Since then, he’s worked in a variety of IT positions. He specializes in Windows image capture, customization, repair and deployment as well as Hyper-V virtualization. Kari is a proud Team Member at number #1 Windows site TenForums.com.