The Microsoft Copilot SDK, called the GitHub Copilot SDK before version 2.0, is a software development kit that lets you drive the agent runtime behind Copilot CLI from your own Python code. You install it with pip, open a session, and send a prompt. The agent then plans the work, calls tools, and edits files on its own. You can hand it custom Python functions, watch its progress live, and run it unattended as a CI check.
By the end of this tutorial, you’ll understand that:
- The SDK exposes a programmable agent runtime that handles the tool loop, file edits, permissions, and session state for you.
- The
@define_tooldecorator and a Pydantic model turn a regular Python function into a tool that the agent can call. - Enabling streaming and registering a handler with
.on()give you live events for message deltas and tool calls. - A permission handler limits which reads, writes, and shell commands the agent may perform, so an unattended run in CI can review code without changing it.
- Each prompt runs a full agent and is billed like a Copilot CLI prompt. For a single structured completion, a raw model call skips the agent’s overhead and costs less.
If you’ve used GitHub Copilot CLI, then you’ve already met this agent in your terminal. The SDK puts the same agent inside your Python programs. If you want a broader view of the tools in this space, then check out the AI coding agents guide.
In this tutorial, you’ll write a minimal agent and then extend it in three small scripts. Along the way, you’ll find out where the SDK fits well and where another tool would serve you better.
Get Your Code: Click here to download the free sample code you’ll use to build an issue tracker agent, a live refactoring agent, and a read-only CI reviewer with the Microsoft Copilot SDK.
Take the Quiz: Test your knowledge with our interactive “Copilot SDK: Put a Coding Agent in Your Python Code” quiz. You’ll receive a score upon completion to help you track your learning progress:
Interactive Quiz
Copilot SDK: Put a Coding Agent in Your Python CodeTest your understanding of the Microsoft Copilot SDK, from running a Python agent to custom tools, live events, and read-only CI checks.
AI Agent From Scratch Live Course: Curious what the SDK’s tool loop is doing for you under the hood? In Real Python’s Build an AI Agent From Scratch in Python live course, you build the agent loop by hand, then recognize every piece of it in the tools you already use. Join the waitlist to hear about the next dates.
Get Started With the Microsoft Copilot SDK
The SDK’s README describes it as a library that:
[…] exposes the same engine behind Copilot CLI: a production-tested agent runtime you can invoke programmatically. (Source)
By default, the SDK loads that runtime into your Python process as a native library, so you never install or manage a separate server yourself.
Note: On November 17, 2026, the GitHub Copilot SDK was renamed to the Microsoft Copilot SDK and released as version 2.0. The PyPI package changed from github-copilot-sdk, which is now deprecated, to microsoft-copilot-sdk, but you still import it as copilot.
Version 2.0 also changed the API, so code written for version 1, with arguments such as github_token or on_permission_request, won’t run unchanged. This tutorial uses version 2.
Why not call a model API directly instead? You could, but then you’d have to build the agent around it yourself. Here’s what the SDK gives you out of the box:
- The tool loop: The agent picks a tool, runs it, reads the result, and repeats until the task is done.
- File edits and shell commands: Built-in tools view, search, and patch files and run shell commands in a working directory.
- Permissions: A handler that you control approves or denies every read, write, or shell command that the agent requests.
- Session state: Each session keeps the conversation, so follow-up prompts build on earlier turns.
To follow along, you need an active GitHub Copilot plan. The SDK also supports bring-your-own-key (BYOK) with your own model provider, which this tutorial doesn’t cover. Any Python version from 3.11 on works, but this tutorial uses Python 3.14. The SDK’s API is asynchronous, so some familiarity with async I/O in Python will help you read the examples. You should also understand virtual environments and type hints.
Install the SDK and Its Runtime
The demos let the agent write files and run shell commands, so you’ll run them inside a Docker container for security reasons.
Note: An agent that can run shell commands can do anything your user account can. A Python virtual environment isolates your packages, but not the agent. A container limits what the agent sees to the folder you mount, so a wrong command can’t touch the rest of your system. If you can’t run Docker, then a throwaway virtual machine gives you the same protection.
Create a project folder and start a Python container that mounts it:
$ mkdir copilot-sdk/
$ cd copilot-sdk/
$ docker run -it --rm -v "$PWD":/app -w /app python:3.14 bash
The -v option shares your project folder with the container as /app. You don’t need an editor inside the container. Write each script with your usual editor in copilot-sdk/ on your computer, and it shows up in /app right away. Then run it from the container’s shell, which you keep open for the rest of the tutorial. The --rm option deletes the container when you exit that shell.
Note: Inside the container, your prompt will look something like root@b701ffb20e1e:/app#, with your container’s ID. This tutorial shortens it to $.
Inside the container, create and activate a virtual environment, then install the SDK together with Pydantic, which you’ll use for tool parameters later:
$ python -m venv .venv/
$ source .venv/bin/activate
(.venv) $ python -m pip install microsoft-copilot-sdk==2.0.6 \
pydantic==2.14.4
(.venv) $ python -m copilot download-runtime --in-process