Tools & Permissions
Prerequisites
- Completed Modules 1-4
- Understanding of command-line security concepts
- A test directory for safe experimentation
Learning Objectives
- Understand Copilot CLI's built-in tools
- Master the permission approval workflow
- Use
--allow-tooland--deny-toolflags effectively - Understand
--yolomode and when to use it safely - Configure trusted directories
Concepts
Built-in Tools
Copilot CLI includes several built-in tools:
| Tool | Purpose | Risk Level |
|---|---|---|
shell | Execute shell commands | ⚠️ High |
write | Create/modify files | ⚠️ High |
read | Read file contents | Low |
show_file | Present code/diffs to user in a prominent view (v0.0.415+) | Low |
web_fetch | Fetch web content | Medium |
mcp | Use MCP server tools | Varies |
Permission Model
Every potentially destructive action requires approval:
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Copilot │────▶│ Permission │────▶│ Execute │
│ wants to │ │ Prompt │ │ Action │
│ use tool │ │ │ │ │
└─────────────┘ └──────────────┘ └─────────────┘
│
▼
┌──────────────┐
│ User │
│ Decides │
└──────────────┘
Approval Levels
- One-time - Approve this specific invocation only
- Session-wide - Approve this tool for the entire session
- Deny - Reject and provide alternative guidance
Hands-On Exercises
Exercise 1: Understanding Tool Prompts
Goal: Learn to read and respond to tool approval prompts.
Steps:
-
Create a test directory:
mkdir -p ~/copilot-tools-lab && cd ~/copilot-tools-lab
git init -
Start Copilot:
copilot -
Request a file operation:
Create a file called test.txt with "Hello World" -
Observe the tool approval prompt. It shows:
- Tool name:
write - File path:
test.txt - Content preview
- Three approval options
- Tool name:
-
Select Yes (one-time approval).
-
Now request another file:
Create another file called test2.txt -
Notice you're prompted again (one-time didn't persist).
-
This time select Yes, and approve write for the rest of the session.
-
Request a third file:
Create test3.txt -
No prompt this time - session approval persists.
-
To reset all approved tools for the session, use:
/reset-allowed-tools -
Now request another file operation:
Create test4.txt -
Notice you're prompted again - the reset cleared all session approvals.
Expected Outcome: You understand the difference between one-time and session-wide approval, and can reset session approvals when needed.
Exercise 2: Shell Command Approval
Goal: Safely approve shell commands with granular control.
Steps:
-
In the same session:
List all files in the current directory -
Copilot requests
shell(ls). Approve for session. -
Now try:
Show me the disk usage of this directory -
Copilot requests
shell(du). This is a different command! -
Approve
dufor session as well. -
Request something more dangerous:
Delete the test.txt file -
Copilot requests
shell(rm). Select No and explain:I don't want to delete files right now. Just show me what would be deleted. -
Copilot adjusts its approach without executing
rm.
Expected Outcome: Shell commands are approved individually by command name.
Exercise 3: Using --allow-tool Flag
Goal: Pre-approve tools for programmatic mode.
Steps:
-
Exit the interactive session.
-
Run with specific tool allowance:
copilot -p "Show me all .txt files" --allow-tool 'shell(ls)' -
Allow multiple read-only commands:
copilot -p "Show git status and recent commits" \
--allow-tool 'shell(git status)' \
--allow-tool 'shell(git log)' -
Allow all shell commands (be careful!):
copilot -p "Analyze this directory structure" --allow-tool 'shell' -
Allow file writing:
copilot -p "Create a README.md with project description" --allow-tool 'write'
Expected Outcome: Commands execute without interactive prompts.
Exercise 4: Using --deny-tool Flag
Goal: Explicitly block dangerous operations.
Steps:
-
Allow all tools but block dangerous ones:
copilot -p "Help me clean up this project" \
--allow-all-tools \
--deny-tool 'shell(rm)' \
--deny-tool 'shell(rm -rf)' -
Block git push while allowing other git:
copilot -p "Commit these changes with a good message" \
--allow-tool 'shell(git)' \
--deny-tool 'shell(git push)' -
Block file modifications:
copilot -p "Review this codebase" \
--allow-tool 'shell' \
--deny-tool 'write' -
Create a safe analysis mode:
copilot -p "Analyze security issues" \
--allow-tool 'shell(cat)' \
--allow-tool 'shell(grep)' \
--allow-tool 'shell(find)' \
--deny-tool 'shell(rm)' \
--deny-tool 'shell(mv)' \
--deny-tool 'write'
Expected Outcome: Deny rules take precedence over allow rules.
Exercise 5: YOLO Mode (Careful!)
Goal: Understand fully autonomous execution.
Steps:
Only use --yolo in safe, isolated environments!
-
Create an isolated test directory:
mkdir -p ~/yolo-test && cd ~/yolo-test
echo "test content" > safe-file.txt -
Run with yolo mode on a safe task:
copilot --yolo -p "Create a Python hello world script" -
Notice: No prompts, file created directly.
-
More complex autonomous task:
copilot --yolo -p "Create a Node.js project with package.json and a simple server" -
Review what was created:
ls -la
cat package.json
When to Use YOLO:
- ✅ Inside Docker containers
- ✅ Disposable dev environments
- ✅ CI/CD pipelines with controlled scope
- ✅ Codespaces that can be reset
When NOT to Use YOLO:
- ❌ Production systems
- ❌ Directories with important data
- ❌ Shared development environments
- ❌ When untrusted input is involved
Expected Outcome: You understand YOLO mode's power and risks.
Exercise 6: Configuring Trusted Directories
Goal: Manage which directories Copilot can access.
Steps:
-
Start Copilot in a new directory:
mkdir -p ~/trusted-test && cd ~/trusted-test
copilot -
When prompted about trusting the folder:
- Yes, proceed - Trust for this session only
- Yes, and remember - Permanently trust
- No, exit - Don't trust
-
Select Yes, proceed for now.
-
Check trusted directories in config:
cat ~/.copilot/config.json -
Manually add trusted directories by editing
config.json:{
"trusted_folders": [
"/home/user/projects",
"/home/user/copilot-workshop"
]
} -
Use
/add-dirat runtime:/add-dir /tmp/safe-dir -
View accessible directories:
/list-dirs
Expected Outcome: You can control directory access both persistently and per-session.
Exercise 7: Creating a Safe Automation Script
Goal: Build a secure automated workflow.
Steps:
-
Create a script
analyze-project.sh:#!/bin/bash
set -e
PROJECT_DIR="${1:-.}"
echo "🔍 Analyzing project in: $PROJECT_DIR"
echo "=================================="
# Safe analysis - read-only operations only
copilot -p "Analyze the code quality and suggest improvements" \
--allow-tool 'shell(find)' \
--allow-tool 'shell(wc)' \
--allow-tool 'shell(grep)' \
--allow-tool 'shell(cat)' \
--allow-tool 'shell(head)' \
--allow-tool 'shell(tail)' \
--deny-tool 'write' \
--deny-tool 'shell(rm)' \
--deny-tool 'shell(mv)' \
--deny-tool 'shell(chmod)' \
--silent -
Create a code review script:
#!/bin/bash
# Review changes but don't modify anything
copilot -p "Review the git diff and provide feedback" \
--allow-tool 'shell(git diff)' \
--allow-tool 'shell(git log)' \
--allow-tool 'shell(git status)' \
--deny-tool 'shell(git push)' \
--deny-tool 'shell(git commit)' \
--deny-tool 'write' -
Make executable and test:
chmod +x analyze-project.sh
./analyze-project.sh
Expected Outcome: Safe, repeatable automation with explicit permissions.
Tool Permission Reference
Allow/Deny Syntax
# Allow specific command
--allow-tool 'shell(git status)'
# Allow command family
--allow-tool 'shell(git)'
# Allow all shell
--allow-tool 'shell'
# Allow file writes
--allow-tool 'write'
# Allow MCP server
--allow-tool 'mcp-server-name'
# Deny takes precedence
--allow-all-tools --deny-tool 'shell(rm)'
Risk Categories
| Category | Commands | Recommendation |
|---|---|---|
| Read-only | ls, cat, grep, find | Safe for session |
| Git read | git status, git log, git diff | Safe for session |
| Git write | git commit, git push | One-time only |
| File modify | touch, echo >, sed -i | Review each use |
| File delete | rm, rm -rf | Always one-time |
| System | chmod, chown, sudo | Deny in automation |
Shorthand Flags
| Flag | Equivalent |
|---|---|
--yolo | --allow-all-tools |
--available-tools | Allowlist specific tools |
--excluded-tools | Denylist specific tools |
Runtime Slash Commands
| Command | Description |
|---|---|
/reset-allowed-tools | Reset the list of tools approved during the session |
/add-dir <path> | Add a trusted directory for the session |
/list-dirs | View accessible directories |
Summary
- ✅ Copilot requires approval for file changes and command execution
- ✅ One-time vs session-wide approval gives granular control
- ✅ Use
/reset-allowed-toolsto clear session approvals - ✅
--allow-tooland--deny-toolenable automation - ✅ Deny rules take precedence over allow rules
- ✅
--yoloenables full autonomy, use only in safe environments - ✅ Trusted directories control Copilot's file access scope
Next Steps
→ Continue to Module 6: MCP Servers