Skip to main content
GitHub Copilot CLI (copilot) is GitHub’s coding agent for the terminal. E2B provides a pre-built copilot template with Copilot CLI already installed.

Authentication

Copilot CLI reads a GitHub token from COPILOT_GITHUB_TOKEN, GH_TOKEN, or GITHUB_TOKEN, in that order. Create a fine-grained personal access token on an account with a Copilot plan, add the Copilot Requests account permission, and pass it to the sandbox as COPILOT_GITHUB_TOKEN. Without a token, copilot -p exits with an error instead of waiting for a login.
Copilot CLI rejects classic personal access tokens (ghp_), even when a model provider is configured. If you use a classic token for git, pass it only to the git command, not as a sandbox-wide GITHUB_TOKEN, as in the cloned repository example.
To use your own model provider instead of a Copilot plan, set COPILOT_PROVIDER_BASE_URL, COPILOT_PROVIDER_API_KEY, and COPILOT_MODEL. No GitHub token is needed in that mode. For OpenAI GPT-5 models, also set COPILOT_PROVIDER_WIRE_API=responses; for Anthropic, set COPILOT_PROVIDER_TYPE=anthropic. Run copilot help providers in the sandbox for all options.

CLI

Create a sandbox with the E2B CLI and pass your token to the terminal session.
Once inside the sandbox, start Copilot CLI.
If you did not pass a token, run /login in Copilot CLI to sign in with your GitHub account.

Run headless

Use -p for non-interactive mode and --allow-all-tools to auto-approve all tool calls. Without it, headless runs cannot ask for approval: tools that need it are denied, and the run still exits with code 0. Add -s to print only the final answer. Agent runs often take longer than the default command timeout, so pass timeoutMs: 0 (timeout=0 in Python) to wait until the run completes, and give the sandbox enough lifetime.
Auto-approving tool calls is contained by the sandbox: the agent cannot touch your host machine, local files, or credentials. It can still make outbound network requests — internet access is enabled by default. To limit where an auto-approved agent can connect, configure outbound network rules (allowInternetAccess, plus allow lists by CIDR or hostname and deny lists by CIDR). Hostname rules apply to HTTP(S) traffic only; use CIDR rules for other protocols.
Select a model with --model, or with COPILOT_MODEL when you use your own provider. To allow only some tools, replace --allow-all-tools with --allow-tool and --deny-tool rules, for example --allow-tool='shell(git:*)' --deny-tool='shell(git push)'.

Example: work on a cloned repository

Streaming events

Use --output-format json to get a JSONL event stream: assistant.message_delta events with response text, tool.execution_start and tool.execution_complete events for tool calls, and a final result event with the session ID and the files the run changed.

Resume a session

Copilot CLI stores sessions in ~/.copilot inside the sandbox. Use --continue to resume the most recent one, or --resume=<session-id> with the ID from the result event, to give follow-up instructions with the earlier context.
To keep sessions across sandbox restarts, pause the sandbox instead of killing it.

Build a custom template

If you need to customize the environment (e.g. pre-install dependencies, add config files), build your own template on top of the pre-built copilot template.
Run the build script to create the template.

Cookbook example

Run Copilot CLI on a repository and print the diff

Sandbox persistence

Auto-pause, resume, and manage sandbox lifecycle

SSH access

Connect to the sandbox via SSH for interactive sessions