Lesson 1 of 3 Agents and Runners

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.

True or false

How an agent gets its work

Exam skills 3.3.2

Check how agents and runners receive and run jobs.

Log in to try this activity Interactive activities are free with an account.

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.

ItemMicrosoft-hosted (Azure Pipelines)GitHub-hosted (standard)
Linux and Windows hardware2 cores, 7 GB RAM, 14 GB SSD2 CPUs and 8 GB RAM on private repositories; 4 CPUs and 16 GB RAM on public repositories
Image labelsubuntu-latest, windows-latest, macOS-latestubuntu-latest, windows-latest, macos-latest
Job time limit60 minutes on the free tier; 360 minutes when paid6 hours
Selecting a machinepool: vmImageruns-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.

Scenario questions

Living with hosted machines

Exam skills 3.3.2

Apply the limits and behaviour of hosted agents and runners.

Log in to try this activity Interactive activities are free with an account.

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.

A self-hosted agent inside the on-premises network. The agent connects outward over HTTPS to Azure Pipelines, which the firewall allows, and reaches the SQL Server locally; no inbound rule is needed. A Microsoft-hosted agent cannot reach the private network.
The scenario is illustrative.
Sort into groups

Hosted or self-hosted?

Exam skills 3.3.2

Decide whether each job needs a self-hosted machine or can use a hosted one.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

Check yourself

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.