Skip to content

How to Enable Windows Sandbox from a Batch Script

Automate Windows Sandbox setup using a Batch script with DISM or PowerShell, including prerequisites, troubleshooting, and best practices for Pro/Enterprise editions.

Windows Sandbox is a game-changer for security-conscious users, providing a pristine, isolated Windows environment to test suspicious applications without risking the host system. However, the feature is disabled by default. Manually enabling it through the "Windows Features" menu is a multi-step process that many users find tedious. By using a Batch script, you can automate the enablement of the Sandbox, the "Virtual Machine Platform," and all other necessary sub-components with a single click.

This guide explains how to use the DISM utility to prepare your system for professional-grade isolation.

Prerequisites for Enabling Sandbox

Before running the enablement script, ensure your machine meets these criteria:

  • Windows Edition: Must be Pro, Enterprise, or Education (Home edition is not supported).
  • Virtualization: Must be enabled in your BIOS/UEFI settings (often called "Intel VT-x" or "AMD-V").

The Deployment Image Servicing and Management (DISM) utility is the most reliable way to manage Windows components from a script.

@echo off
setlocal

echo ============================================================
echo   ENABLER: Windows Sandbox Automated Setup
echo ============================================================

:: 1. Check for Administrative Privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] This script must be run as Administrator.
    pause
    exit /b 1
)

:: 2. Check if already enabled
dism /online /get-featureinfo /featurename:Containers-DisposableClientVM 2>nul | findstr /i /c:"State" | findstr /i /c:"Enabled" >nul
if %errorlevel% equ 0 (
    echo [INFO] Windows Sandbox is already enabled.
    pause
    exit /b 0
)

:: 3. Enable the Sandbox feature
echo [PROCESS] Enabling Windows Sandbox...
:: The internal feature name is "Containers-DisposableClientVM"
dism /online /enable-feature /featurename:Containers-DisposableClientVM /all /norestart

if %errorlevel% equ 0 (
    echo [SUCCESS] Windows Sandbox has been enabled.
    echo [IMPORTANT] You MUST restart your computer to finalize this!
) else if %errorlevel% equ 3010 (
    echo [SUCCESS] Enabled successfully. REBOOT REQUIRED.
) else (
    echo [ERROR] Enablement failed. Error code: %errorlevel%
    echo [HELP] Ensure this is not Windows Home edition and that
    echo [HELP] virtualization is enabled in your BIOS.
)

echo ============================================================
pause

Explaining the Flags:

  • /online: Targets the currently running operating system.
  • /featurename:Containers-DisposableClientVM: The unique internal ID for Windows Sandbox.
  • /all: Ensures all parent features (like the Virtual Machine Platform) are enabled automatically.
  • /norestart: Prevents the script from forcing an immediate, unsaved reboot.

Method 2: Enabling via PowerShell (Bridge)

If you prefer using the modern Enable-WindowsOptionalFeature cmdlet, you can call it from your Batch file.

@echo off

:: Check for Administrative Privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] This script must be run as Administrator.
    pause
    exit /b 1
)

echo [PROCESS] Enabling Sandbox via PowerShell...

powershell -NoProfile -Command "Enable-WindowsOptionalFeature -Online -FeatureName 'Containers-DisposableClientVM' -All -NoRestart"

if %errorlevel% equ 0 (
    echo [SUCCESS] Windows Sandbox has been enabled.
    echo [IMPORTANT] You MUST restart your computer to finalize this!
) else (
    echo [ERROR] Enablement failed. Error code: %errorlevel%
)

pause

Common Pitfalls and How to Avoid Them

The "Feature Not Found" Error

If your script returns an error saying the feature cannot be found, it is almost always because the computer is running Windows Home Edition.

Wrong Way:

:: Trying to force install Sandbox on Windows Home
dism /online /enable-feature ...
:: Result: Error 0x800f080c (Feature name unknown)

Correct Way: Before enabling, check the OS edition (see our guide on "How to Detect Windows Edition"). If Home is detected, warn the user that they must upgrade to Pro or use a third-party tool like VirtualBox.

Virtualization Block (Error 0x80370102)

Even after running this script successfully, the Sandbox icon might appear, but clicking it results in an error if virtualization is off in the BIOS.

Best Practices for Successful Setup

  1. Check for Pending Updates: Sometimes, enabling features can fail if Windows Update has a pending restart. Run your script on a "clean" system state.
  2. Combine with Hyper-V: If you also need full virtual machines, you can enable Hyper-V in the same script:
    dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /all /norestart
  3. Automatic Reboot: If you are sure the user has saved their work, you can change /norestart to /restart to immediately finalize the installation.

Conclusion

Enabling Windows Sandbox via Batch script is a professional and efficient way to standardize your security and testing environment. By automating the activation of the Containers-DisposableClientVM feature and its dependencies, you provide a repeatable setup process that eliminates manual configuration errors. This automated approach ensures that your system is always prepared for isolated software evaluation, maintaining the integrity and security of your host environment while providing the freedom to test anything without consequence.

Navigation