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 fromCOPILOT_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.
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./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.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.
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-builtcopilot template.
Related guides
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