---
title: "GitHub Copilot CLI integration"
description: "Run GitHub Copilot CLI headless in an E2B sandbox from the prebuilt copilot template, with full filesystem, terminal and git access."
url: "https://e2b.dev/integrations/copilot-cli"
---

# GitHub Copilot CLI

> Run GitHub Copilot CLI in an E2B sandbox with a real filesystem, terminal and git. Auto-approved tool calls stay in the sandbox, not on your machine.

Coding agents · [All integrations](https://e2b.dev/integrations.md)

## About this integration

- **Maintained by:** E2B
- **How it works:** Prebuilt copilot template
- **Template:** copilot
- **Language:** TypeScript, Python
- **Upstream:** [github/copilot-cli · ★ 11k](https://github.com/github/copilot-cli)
- **Example:** [e2b-cookbook/github-copilot-cli-in-sandbox-js](https://github.com/e2b-dev/e2b-cookbook/tree/main/examples/github-copilot-cli-in-sandbox-js)

## Get started

Paste the prompt into your coding agent, or follow the steps yourself.

### Paste this into your coding agent

```text
Run GitHub Copilot CLI in an E2B sandbox from this project.

1. Install the e2b package using the project's package manager.
2. The SDK needs the E2B_API_KEY environment variable. If it isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode it. Copilot also needs COPILOT_GITHUB_TOKEN, a fine-grained token with the Copilot Requests permission.
3. Follow the GitHub Copilot CLI guide at https://docs.e2b.dev/agents/copilot-cli: create a sandbox from the copilot template and run copilot --allow-all-tools -p with a task and timeoutMs: 0.
4. Run it once, show me the output that came from the sandbox, then kill the sandbox.
```

## Or set it up yourself

### 1. Install the E2B SDK

```bash
npm i e2b
```

### 2. Set your keys

```bash
export E2B_API_KEY="e2b_..."
export COPILOT_GITHUB_TOKEN="github_pat_..."
```

### 3. Run Copilot headless

```typescript
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('copilot', {
  envs: { COPILOT_GITHUB_TOKEN: process.env.COPILOT_GITHUB_TOKEN! },
  timeoutMs: 600_000,
})

const result = await sandbox.commands.run(
  `copilot --allow-all-tools -p "Create a hello world HTTP server in Python"`,
  { timeoutMs: 0 }
)

console.log(result.stdout)
await sandbox.kill()
```

### 4. Or open it interactively

```bash
e2b sbx create copilot -e COPILOT_GITHUB_TOKEN=$COPILOT_GITHUB_TOKEN
copilot
```

## What runs in the sandbox

Copilot's auto-approved tool calls run in the sandbox, away from your host files and credentials.

- **Code:** Shell commands, file edits and git operations Copilot runs with --allow-all-tools, or only the tools you allow with --allow-tool.
- **State:** Sessions are stored in ~/.copilot in the sandbox. --continue resumes the latest and --resume picks one by ID.
- **Secrets:** Pass a fine-grained COPILOT_GITHUB_TOKEN. Give a git token only to the git command, not as a sandbox-wide env.
- **Network:** Sandboxes reach the internet by default. Limit where the agent connects with outbound network rules.

## More coding agents

Other coding agents that run in E2B sandboxes.

- [Claude Code](https://e2b.dev/integrations/claude-code.md): Run Claude Code in its own sandbox with a real filesystem, terminal, and git, so it can work unattended.
- [OpenAI Codex](https://e2b.dev/integrations/codex.md): Run OpenAI's Codex CLI headless in a sandbox and collect the diff when it's done.
- [Gemini CLI](https://e2b.dev/integrations/gemini-cli.md): Run Google's Gemini CLI in a sandbox with full filesystem, terminal, and git access.

## Links

- [Get API key](https://console.e2b.dev/?tab=keys)
- [Read the docs](https://docs.e2b.dev/agents/copilot-cli)
- [E2B documentation](https://docs.e2b.dev)
