# Using local sandboxing

Enable local sandboxing so that Copilot 命令行界面（CLI） runs the commands and tools it invokes on your behalf inside an operating-system sandbox.

> \[!NOTE]
> Local sandboxes for GitHub Copilot are in 公开预览 and subject to change.

> \[!IMPORTANT]
> Local sandboxing on Windows requires a Windows Insiders build.

## About local sandboxing

Sandboxing is currently an experimental feature. To use it, start Copilot 命令行界面（CLI） with the `‑‑experimental` command line option, or enter `/experimental on` during a session.

When you enable local sandboxing, Copilot 命令行界面（CLI） runs most of the commands and tools it invokes on your behalf inside an operating-system sandbox. After you enable local sandboxing, it is used for all your Copilot 命令行界面（CLI） sessions until you disable it, or turn it off for a specific session.

By default, sandboxed commands and tools can write within your current working directory and temporary folders. Your user profile (home) directory, along with system and tool locations are read-only. Other disk locations are blocked. In a Git repository, access above the current working directory varies by operating system. Access to your local and private network is permitted, as is outbound internet access.

By default, authenticated Git and GitHub CLI (`gh`) operations continue to work inside the sandbox, because Copilot 命令行界面（CLI） makes your GitHub credentials available to sandboxed commands. This allows actions such as `git push` and `gh pr create` to succeed. You can turn this off in your sandbox settings.

For a conceptual overview of sandboxing in Copilot 命令行界面（CLI）, see [关于 GitHub Copilot](/zh/enterprise-cloud@latest/copilot/concepts/about-cloud-and-local-sandboxes).

## Enabling local sandboxing

To enable local sandboxing, enter the following command in an interactive Copilot 命令行界面（CLI） session:

```shell copy
/sandbox enable
```

Sandboxing starts being used immediately for the current session.

After you enable local sandboxing, it continues to be used for the current and future interactive sessions, and for programmatic sessions.

> \[!NOTE]
> If you have other sessions open when you enter `/sandbox enable`, sandboxing is not immediately used in those sessions. To use sandboxing in an already-open session, do either of the following in that session:
>
> * Close the session and restart it, for example by running `copilot --continue`.
> * Enter `/sandbox enable`.

## Disabling local sandboxing

To stop using local sandboxing, enter the following command in an interactive Copilot 命令行界面（CLI） session:

```shell copy
/sandbox disable
```

Sandboxing is no longer used in the current session, or in new and restarted sessions.

Your choice of whether to use local sandboxing is saved as the `sandbox.enabled` setting in your personal settings file for the CLI (`~/.copilot/settings.json` by default).

## Using sandboxing for a single session

You can use the `--sandbox` command line option to use sandboxing for a single session, without enabling sandboxing for your other sessions. If sandboxing is already enabled, you can disable it for a single session by using the `--no-sandbox` option.

You can combine these options with the `-p` command line option to control sandboxing for programmatic use of the CLI. For example:

```shell copy
copilot --sandbox -p "PROMPT"
```

## Running a single command outside the sandbox

When a command needs broader access than the sandbox allows, Copilot can request to run that single command outside the sandbox. You are shown a confirmation prompt describing the command, and it runs outside the sandbox only if you approve it; otherwise it stays sandboxed. The rest of your session remains sandboxed either way.

This behavior is enabled by default and can be turned off in your sandbox settings.

## Checking whether sandboxing is being used

To check whether sandboxing is being used for the current session, look at the status line. If sandboxing is being used, the status line contains `sandbox enabled`.

Display of sandbox information in the status line is turned on by default. If it is turned off, you can turn it back on:

1. Enter `/statusline`.
2. Move the selection down the list of options to **sandbox**.
3. Press <kbd>Enter</kbd> to toggle the setting so that it shows a check mark.

## Further reading

* [关于 GitHub Copilot](/zh/enterprise-cloud@latest/copilot/concepts/about-cloud-and-local-sandboxes)
* [配置本地沙盒设置](/zh/enterprise-cloud@latest/copilot/how-tos/cloud-and-local-sandboxes/configuring-local-sandbox-settings)