This commit is contained in:
Vinay Pamnani (from Dev Box) 2024-10-22 10:44:07 -06:00
parent 163e60675e
commit e6613bb5f4
5 changed files with 133 additions and 6 deletions

View File

@ -4,7 +4,7 @@ items:
- name: Overview - name: Overview
expanded: true expanded: true
items: items:
- name: Compare versions - name: Windows Sandbox versions
href: windows-sandbox-versions.md href: windows-sandbox-versions.md
- name: Architecture - name: Architecture
href: windows-sandbox-architecture.md href: windows-sandbox-architecture.md
@ -12,6 +12,8 @@ items:
href: windows-sandbox-install.md href: windows-sandbox-install.md
- name: Use & configure Windows Sandbox - name: Use & configure Windows Sandbox
href: windows-sandbox-configure-using-wsb-file.md href: windows-sandbox-configure-using-wsb-file.md
- name: Windows Sandbox command line interface
href: windows-sandbox-cli.md
- name: Tutorials - name: Tutorials
items: items:
- name: Sample configuration files - name: Sample configuration files

View File

@ -0,0 +1,101 @@
---
title: Windows Sandbox command line
description: Windows Sandbox command line interface
ms.topic: how-to
ms.date: 10/22/2024
---
# Windows Sandbox command line interface
Starting with Windows 11, version 24H2, the Windows Command Line Interface (CLI) offers powerful tools for creating, managing, and controlling sandboxes, executing commands, and sharing folders within sandbox sessions. This functionality is especially valuable for scripting, task automation, and improving development workflows. In this section, you'll explore how the Windows Sandbox CLI operates, with examples demonstrating how to use each command to enhance your development process.
**Common parameters**:
- `--raw`: Formats all outputs in JSON format.
- `-?, -h, --help`: Show help and usage information
## Start
The start command creates and launches a new sandbox. The command returns the sandbox ID, which is a unique identifier for the sandbox. The sandbox ID can be used to refer to the sandbox in other commands.
- `--id <id>`: ID of the Windows Sandbox environment.
- `--c, --config <config>`: Formatted string with the settings that should be used to create the Windows Sandbox environment.
**Examples**:
- Create a Windows Sandbox environment with the default settings:
```cmd
wsb start
```
- Create a Windows Sandbox environment with a custom configuration:
```cmd
wsb start --config "<configuration><Networking>Disabled</Networking>"
```
## List
The list command displays a table that shows the information the running Windows Sandbox sessions for the current user. The table includes the sandbox ID. The status can be either running or stopped. The uptime is the duration that the sandbox has been running.
```cmd
wsb list
```
## Exec
The exec command executes a command in the sandbox. The command takes two arguments: the sandbox ID and the command to execute. The command can be either a built-in command or an executable file. The exec command runs the command in the sandbox and returns the exit code. The exec command can also take optional arguments that are passed to the process started in the sandbox.
> [!NOTE]
> Currently, there is no support for process I/O meaning that there is no way to retrieve the output of a command run in Sandbox.
Commands in Windows Sandbox can be executed in the system context or in the context of the currently logged on user. However, there is no way to log on a user without an active RDP session. Therefore, there currently is no way to execute commands in the user context unless there is an active RDP session.
- `--id <id>` (REQUIRED): ID of the Windows Sandbox environment.
- `-c, --command <command>` (REQUIRED): The command to execute within Windows Sandbox.
- `-r, --run-as <ExistingLogin|System>` (REQUIRED): Specifies the user context to execute the command within. If the System option is selected, the command will run in the system context. If the ExistingLogin option is selected, the command will run in the currently active user session or fail if there is no active user session.
- `-d, --working-directory <directory>`: Directory to execute command in.
```cmd
wsb exec -id 12345678-1234-1234-1234-1234567890AB -c app.exe -r System
```
## Stop
The stop command stops a running Windows Sandbox session. The command takes the sandbox ID as an argument.
The stop command terminates the sandbox process and releases the resources allocated to the sandbox. The stop command also closes the window that shows the sandbox desktop.
```cmd
wsb stop --id 12345678-1234-1234-1234-1234567890AB
```
## Map
The map command maps a host folder to a folder in the sandbox. The command takes three arguments: the sandbox ID, the host path, and the sandbox path. The host path should be a folder. The sandbox path can be either an existing or a new folder. The share command allows the user to share files and folders between the host and the sandbox. An Additional, `--allow-write` option can be used to allow or disallow the Windows Sandbox environment to write to the folder.
- `--id <id>` (REQUIRED): ID of the Windows Sandbox environment.
- `-f, --host-path <host-path>` (REQUIRED): Path to folder that will be mapped from the host.
- `-s, --sandbox-path <sandbox-path>` (REQUIRED): Path to the folder within the Windows Sandbox.
- `-w, --allow-write`: If specified, the Windows Sandbox environment will be allowed to write to the shared folder.
```cmd
wsb map --id 12345678-1234-1234-1234-1234567890AB -f C:\host\folder -s C:\sandbox\folder --allow-write
```
## Connect
The connect command starts a remote session within the sandbox. The command takes the sandbox ID as an argument. The connect command opens a new window with a remote desktop session. The connect command allows the user to interact with the sandbox using the mouse and keyboard.
```cmd
wsb connect --id 12345678-1234-1234-1234-1234567890AB
```
## IP
The ip command displays the IP address of the sandbox. The command takes the sandbox ID as an argument.
```cmd
wsb ip --id 12345678-1234-1234-1234-1234567890AB
```

View File

@ -7,7 +7,7 @@ ms.date: 09/09/2024
# Use and configure Windows Sandbox # Use and configure Windows Sandbox
To launch a Windows Sandbox with default settings, locate and select Windows Sandbox on the Start menu or search for 'Windows Sandbox'. This launches a basic Sandbox with 4GB memory with the following properties: To launch a Windows Sandbox with default settings, locate and select Windows Sandbox on the Start menu or search for 'Windows Sandbox'. This launches a basic Sandbox with maximum capacity of 4GB memory with the following properties:
- **vGPU (virtualized GPU)**: Enabled on non-ARM64 devices. - **vGPU (virtualized GPU)**: Enabled on non-ARM64 devices.
- **Networking**: Enabled. The sandbox uses the Hyper-V default switch. - **Networking**: Enabled. The sandbox uses the Hyper-V default switch.
@ -231,4 +231,4 @@ Specifies the amount of memory that the sandbox can use in megabytes (MB).
<MemoryInMB>value</MemoryInMB> <MemoryInMB>value</MemoryInMB>
``` ```
If the memory value specified is insufficient to boot a sandbox, it's automatically increased to the required minimum amount. If the memory value specified is insufficient to boot a sandbox, it's automatically increased to the required minimum amount of 2048 MB.

View File

@ -75,9 +75,9 @@ C:\temp\vscode.exe /verysilent /suppressmsgboxes
## Example 3 - Mapping Folders and running a PowerShell script as a Logon Command ## Example 3 - Mapping Folders and running a PowerShell script as a Logon Command
The following config file runs a PowerShell script as a logon command to swap the primary mouse button for left-handed users. Beginning in Windows 11, version 24H2, Windows Sandbox adheres to the mouse settings of the host system. If you are on an older build and if the host system is set to use a left-handed mouse, you must apply these settings in Windows Sandbox manually when Windows Sandbox starts. Alternatively, you can use a sandbox configuration file to run a logon command to swap the mouse setting.
`C:\sandbox` folder on the host is mapped to the `C:\sandbox` folder in the sandbox, so the `SwapMouse.ps1` script can be referenced in the sandbox configuration file. In this example, the `C:\sandbox` folder on the host is mapped to the `C:\sandbox` folder in the sandbox, so the `SwapMouse.ps1` script can be referenced in the sandbox configuration file.
### SwapMouse.ps1 ### SwapMouse.ps1

View File

@ -2,7 +2,31 @@
title: Windows Sandbox versions title: Windows Sandbox versions
description: Windows Sandbox versions description: Windows Sandbox versions
ms.topic: conceptual ms.topic: conceptual
ms.date: 09/09/2024 ms.date: 10/22/2024
--- ---
# Windows Sandbox versions # Windows Sandbox versions
Starting with Windows 11, version 24H2, a newer version of Windows Sandbox is available from the Microsoft Store, featuring an improved user experience and new command line functionality.
- **Faster Updates**: With the app now being updated through the Microsoft Store, you can install the bug fixes and new features as soon as they're available, rather than needing to wait for an update of the Windows operating system.
- **Revamped UI**: The app now features WinUI 3, a modern and sleek user interface built on the Fluent design system.
- **New Runtime Features**: Users can now access clipboard redirection, audio/video input control, and folder sharing directly during runtime using the "…" icon in the top-right corner. No need for pre-configured .wsb files.
- **Command Line Preview**: We've introduced an early version of command line support for Windows Sandbox. Check out ---- for more details.
## Upgrading to the newer version
### Prerequisites
- Windows Sandbox must already be installed. If it isn't already installed, [install Windows Sandbox](windows-sandbox-install.md).
- Device must be running Windows 11, version 24H2, with KB10D or later.
- Microsoft Store and Windows Update must be accessible.
### Upgrade
- Launch **Windows Sandbox** from the Start menu.
- If the app hasn't been upgraded to the latest version, a progress dialog appears as it automatically attempts to update. This process typically takes 30 seconds to 2 minutes.
- Once the installation is complete, you'll be directed to the updated version of the app.
> [!NOTE]
> If the upgrade fails on the first try, the installation continues in the background while you use the older version of the app. Additionally, the app is queued in the "Updates & downloads" section of the Microsoft Store app for users who wish to manually install it.