Understanding Agents and Runners
This lesson explains how agents and runners work, and the hosted and self-hosted options.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how an agent connects to the service.
- Describe hosted agents and runners.
- Explain when self-hosted machines are needed.
- Select machines with demands and labels.
How agents and runners work
An agent in Azure Pipelines, or a runner in GitHub Actions, is software on a machine. It connects outward to the service over HTTPS and asks for work. When a job arrives, it downloads the steps, runs them and streams logs back. Because it polls outward, a self-hosted agent needs no inbound firewall rule, which is the fact behind many exam scenarios.
A job needs an agent to be available. If none is free, the job queues. An Azure Pipelines agent belongs to an agent pool, and a GitHub runner is registered at repository, organization or enterprise level, where organization and enterprise runners can be arranged in runner groups.
How an agent gets its work
Hosted agents and runners
Microsoft-hosted agents and GitHub-hosted runners are virtual machines maintained by the provider. Each job receives a fresh image with common tools already installed, and the machine is discarded afterwards. This gives isolation and predictable builds, with no patching to do. The disadvantages are limited specifications, no default access to private networks, and no cache between jobs unless a cache step is used.
Specifications differ between platforms, as the following table shows. Microsoft-hosted agents use Standard_DS2_v2 virtual machines.
| Item | Microsoft-hosted (Azure Pipelines) | GitHub-hosted (standard) |
|---|---|---|
| Linux and Windows hardware | 2 cores, 7 GB RAM, 14 GB SSD | 2 CPUs and 8 GB RAM on private repositories; 4 CPUs and 16 GB RAM on public repositories |
| Image labels | ubuntu-latest, windows-latest, macOS-latest | ubuntu-latest, windows-latest, macos-latest |
| Job time limit | 60 minutes on the free tier; 360 minutes when paid | 6 hours |
| Selecting a machine | pool: vmImage | runs-on |
A -latest label moves to a newer image over time, so a build can change without a code change. Naming a specific image, such as ubuntu-24.04, keeps it stable until that image is retired. At the time of writing, ubuntu-latest is Ubuntu 24.04, the Ubuntu 22.04 Azure Pipelines image is scheduled for removal on 17 April 2027, and the Windows Server 2019 image is retired.
Living with hosted machines
Self-hosted agents and runners
A self-hosted agent or runner is a machine that you provide, which may be physical, virtual or a container, in any cloud or datacentre. It is the answer when a job needs something that a hosted machine cannot offer.
- Access to private networks, such as an on-premises database or a server in a virtual network.
- Special hardware, such as a GPU, or software with its own licence.
- Persistent caches and incremental builds, which can greatly reduce build time.
- Unusual operating systems, or job durations beyond hosted limits.
The trade-off is responsibility. You patch the operating system, update tools, secure the machine and clean up after jobs. Because state persists between jobs, one job can affect the next, whether through a stale file or a malicious pull request. Azure Pipelines has no time limit on self-hosted jobs. GitHub limits a self-hosted job to 5 days.
Selecting self-hosted machines
Azure Pipelines selects agents through capabilities and demands. An agent reports capabilities, such as installed software, and a job states demands. GitHub uses labels and groups, where a job must match all listed labels.
# Azure Pipelines
pool:
name: linux-build
demands:
- docker
- Agent.OS -equals Linux
# GitHub Actions
runs-on: [self-hosted, linux, x64, gpu]
# GitHub Actions with a runner group
runs-on:
group: build-runners
labels: [linux]Do not use self-hosted runners with public GitHub repositories. A pull request from a fork could run arbitrary code on your machine, and a persistent machine lets that code remain. Ephemeral runners, which take one job and are destroyed, greatly reduce this risk.
The following diagram shows a self-hosted agent's outbound connection to Azure Pipelines and its path to an on-premises database.

Hosted or self-hosted?
Reaching a private database
A pipeline in Azure Pipelines must run integration tests against a SQL Server in an on-premises network. The firewall allows outbound HTTPS, but the network team refuses inbound rules. What should you recommend?
Install a self-hosted agent on a machine inside the network. The agent connects outward over HTTPS and needs no inbound rule, and from there it can reach the database. A Microsoft-hosted agent cannot reach the private network, and allowing Azure's IP ranges into the firewall would violate the rule and expose the server unnecessarily.
Why does a self-hosted agent need no inbound firewall rule?
Show answer
It connects outward over HTTPS and polls for jobs, so the service never connects to it.
Exam Tips
Remember for the exam
- Agents and runners connect outward, so no inbound rule is needed.
- Hosted machines are fresh for each job and need no patching.
- A -latest label can change; name an image for stability.
- Azure Pipelines uses demands; GitHub Actions uses labels and groups.
- Do not use self-hosted runners on public repositories.