GitHub Copilot CLI puts an AI agent in PowerShell. You type a request, and it can read your files, edit them, run your tests, use git and gh, and open a pull request for you. That is useful, and it also means the agent runs with your user account's access unless you tell it otherwise.
This post is the setup I would hand a teammate on Windows: install it, then decide what it may touch before you start giving it real work. Every command and option below comes from GitHub's own Copilot CLI docs.
TL;DR
- Install with
winget install GitHub.Copilot(ornpm install -g @github/copiloton Node.js 22+), runcopilotin a project folder, then/login. - Never start it in your user profile folder. The folder you launch from is the folder you are trusting.
- "Approve for the rest of the session" approves the whole tool, not just that one command.
- Use
--deny-toolfor the commands you never want run unattended, such asgit push. Deny always wins over allow. - On a recent Windows 11 build,
/sandbox enableruns the agent's commands in an OS sandbox. It is off by default.
Install and sign in
Copilot CLI runs on Windows from PowerShell or inside WSL. GitHub lists Windows PowerShell 5.1 as supported too, so you do not need PowerShell 7 for this.
# WinGet
winget install GitHub.Copilot
# or npm (needs Node.js 22 or later)
npm install -g @github/copilot
There is also a GitHub.Copilot.Prerelease WinGet package if you want early builds.
Then go to a project and start it:
cd C:\src\my-app
copilot
On first launch, type /login and follow the prompts. You need an active Copilot plan, your own model provider, or an eligible Microsoft Entra account. For scripts and CI, GitHub also supports a fine-grained personal access token with the "Copilot Requests" permission, read from COPILOT_GITHUB_TOKEN, GH_TOKEN or GITHUB_TOKEN, in that order.
Step 1: Pick the folder you trust
When you start copilot, it asks whether you trust the files in this folder and everything below it. You get three choices: yes for this session, yes and remember the folder, or no.
GitHub's docs are blunt about this. Copilot may read, change and run files under that folder, and you should typically not launch it from your home directory. On Windows that means not from C:\Users\you, where your SSH keys, .azure folder, browser downloads and dotfiles live.
GitHub also says the scoping of permissions is heuristic and is not a guarantee that files outside the trusted folder are protected. Treat the trust prompt as a guardrail, not a wall.
My rule: one repo per session, launched from the repo root, and only "remember this folder" for repos I own.
Step 2: Read the approval prompt carefully
In the default mode, Copilot asks before it runs a tool that changes or executes things. The prompt looks like this:
1. Yes
2. Yes, and approve TOOL for the rest of the running session
3. No, and tell Copilot what to do differently (Esc)
Option 2 is the one to slow down on. GitHub's own example: if Copilot asks to run rm ./this-file.txt and you pick option 2, it can then run any rm command, including rm -rf ./*, for the rest of that session without asking. Those approvals are also restored if you resume the session.
Option 3 is better than people think. You can reject a command and tell Copilot why, and it adapts instead of stopping.
Two more interactive habits worth building:
- Press Shift+Tab to switch into plan mode for anything bigger than a small fix. Copilot asks questions and writes a plan before it touches code.
- Press Esc twice quickly to stop an operation that is going the wrong way.
Step 3: Set allow and deny rules up front
You can decide ahead of time which tools need no approval and which are never allowed. The three flags are:
-
--allow-all-tools: run anything without asking. -
--allow-tool: allow one tool without asking. -
--deny-tool: block one tool. This takes precedence over both allow options.
Tool names look like 'shell(COMMAND)', 'write' for file edits, or an MCP server name. For git and gh you can target a first-level subcommand. Single quotes work as-is in PowerShell:
# Let it work freely, but never push and never delete with rm
copilot --allow-all-tools --deny-tool='shell(rm)' --deny-tool='shell(git push)'
For one-shot jobs, -p runs a single prompt and exits. Give it only the tool it needs:
copilot -p "Show me this week's commits and summarize them" --allow-tool='shell(git)'
One thing I have not seen documented is how deny rules treat PowerShell aliases, for example rm versus Remove-Item. If you rely on a deny rule to block deletes, test it in a throwaway repo first rather than assuming.
Inside an interactive session you also have /permissions assisted, where a model reviews eligible permission requests and approves the ones it judges safe, while anything else still comes to you. There is also /yolo, which does what the name suggests. I would keep that for a sandbox or a disposable VM.
Step 4: Turn on the local sandbox
This is the newest piece and the one that changes the risk picture most. Local sandboxing is off by default, and GitHub says that until you enable it, the commands Copilot runs have the same access as your user account.
Inside a session:
/sandbox enable
/sandbox status
/sandbox policy
Once enabled, it stays on for future interactive and programmatic sessions until you run /sandbox disable. By default, sandboxed commands can write only in the current folder, temp folders and the repo's Git metadata. Outbound internet is on, local network is off. /sandbox policy shows the exact paths and network settings for the current folder, and /sandbox config opens the settings screen.
The Windows requirement is specific: Windows 11 version 25H2 with KB5124010 or later, or version 26H1 with KB5124006 or later. On an older build, GitHub says Copilot reports the requirement rather than quietly running with weaker limits.
Two caveats from the docs:
- The CLI process itself is not sandboxed. Its built-in file tools check the sandbox policy themselves "on a best-effort basis", so this is not the same as running inside a VM.
- If you already have other sessions open, they do not pick up the sandbox until you restart them (for example with
copilot --continue) or run/sandbox enablein each one.
If you need full isolation, copilot --cloud runs the session in a GitHub-hosted cloud sandbox instead of on your PC.
Step 5: Tell it how your repo works
A lot of bad agent runs come from missing context, not a bad model. Copilot CLI reads instruction files automatically:
| File | Scope |
|---|---|
.github/copilot-instructions.md |
The whole repo |
.github/instructions/*.instructions.md |
Specific paths, via applyTo
|
AGENTS.md, CLAUDE.md, GEMINI.md
|
Agent instructions, also picked up |
$HOME/.copilot/copilot-instructions.md |
You, across all repos |
All matching files are combined, with no general precedence order, so avoid rules that contradict each other. /instructions shows which files the current session loaded and lets you switch individual ones off.
A short repo file goes a long way. Something like:
Build with: dotnet build
Test with: dotnet test --no-build
Never edit files under /generated.
Do not run git push. Open a draft PR with gh instead.
Instructions are guidance for the model, not enforcement. Keep the real limits in --deny-tool and the sandbox.
A setup I am comfortable with
Putting it together, this is what I would use for day-to-day work on a Windows dev box:
- Launch from the repo root, never from
C:\Users\you. -
/sandbox enableonce, if your Windows 11 build supports it. - Start with
--deny-tool='shell(git push)'so pushing stays a human step. - Plan mode (Shift+Tab) for anything that touches more than one file.
- A
.github/copilot-instructions.mdwith the build, test and "do not touch" rules.
Keep an eye on usage too. GitHub says each interaction in the CLI consumes AI credits based on tokens processed, and that larger context windows and higher reasoning levels use more. /context shows where your tokens are going.
Your turn
How much freedom do you give a terminal agent on your own machine? Do you approve every command, run it with allow and deny rules, or only let it loose inside a sandbox or VM? And if you have tried /sandbox on Windows yet, did anything in your normal build break inside it?
I wrote a broader guide to the Copilot desktop app, the CLI and VS Code setup on Windows Mode.
Top comments (0)