Skip to main content

Coding agents

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.

Maintained by
E2B
How it works
Prebuilt copilot template
Template
copilot
Language
TypeScript, Python

Set it up

Get started

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

Paste this into your coding agent

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

  1. 1.Install the e2b package using the project's package manager.
  2. 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. 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. 4.Run it once, show me the output that came from the sandbox, then kill the sandbox.

Or set it up yourself

  1. 1. Install the E2B SDK

    npm i e2b
  2. 2. Set your keys

    export E2B_API_KEY="e2b_..."
    export COPILOT_GITHUB_TOKEN="github_pat_..."
  3. 3. Run Copilot headless

    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. 4. Or open it interactively

    e2b sbx create copilot -e COPILOT_GITHUB_TOKEN=$COPILOT_GITHUB_TOKEN
    copilot

Security

What runs in the sandbox

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

  • CodeShell commands, file edits and git operations Copilot runs with -⁠-⁠allow-⁠all-⁠tools, or only the tools you allow with -⁠-⁠allow-⁠tool.
  • StateSessions are stored in ~/.copilot in the sandbox. -⁠-⁠continue resumes the latest and -⁠-⁠resume picks one by ID.
  • SecretsPass a fine-grained COPILOT_GITHUB_TOKEN. Give a git token only to the git command, not as a sandbox-wide env.
  • NetworkSandboxes reach the internet by default. Limit where the agent connects with outbound network rules.

3B+ sandboxes started

Give every agent a machine