L10. Runner and Agent Infrastructure: GitHub-Hosted vs Self-Hosted
Hosted agents need zero maintenance but cannot reach private networks; self-hosted agents solve that at the cost of ownership, and scale set agents split the difference with elastic, network-connected pools.
Hosted Agents vs Self-Hosted Agents
Every pipeline job runs on an agent (Azure Pipelines) or runner (GitHub Actions). You have two fundamental choices. Microsoft-hosted agents and GitHub-hosted runners are fully managed by Microsoft and GitHub respectively. A fresh VM is provisioned for each job, the job runs, and the VM is discarded. Zero maintenance overhead. However:
- They cannot reach private/on-premises networks
- Job time limits apply (GitHub Actions: 6 hours per job)
- Concurrency is limited by your plan (free tier: 20 concurrent jobs)
Decision Factors
Choosing between hosted and self-hosted depends on several criteria:
| Factor | Hosted | Self-Hosted |
|---|---|---|
| Network Access | Public internet only | Private networks, on-prem |
| Maintenance | Zero | Your team patches/upgrades |
| Cost at Scale | High concurrency cost | Low (amortized VM cost) |
| Specialized Tools | Not possible | Install any tool needed |
| Job Duration | Limited | Unlimited |
| Security | Microsoft responsibility | Your team responsibility |
Scale Sets: Elastic Self-Hosted Pools
Azure DevOps scale set agents back a self-hosted agent pool with a VM scale set. The scale set automatically adds VMs when jobs queue up and removes them when idle, combining the private network reach of self-hosted agents with the elastic scaling of hosted agents.This avoids the trade-off: you get self-hosted connectivity and tool customization, plus automatic scaling without managing individual VMs.
Ephemeral vs Persistent Self-Hosted Agents
Ephemeral agents are torn down and rebuilt from scratch after each job, ensuring every job starts clean. No cache, no state leaking between jobs. Persistent agents are reused across jobs. They start faster (no rebuild overhead), but state from one job could leak into another (cached credentials, leftover files, malicious code installed by a previous job).For public repositories, Microsoft and GitHub recommend ephemeral agents or restricting self-hosted runners to private repositories only.
Security Risk: Self-Hosted on Public Repos
A self-hosted runner or agent on a public repository is a significant security risk. A malicious external contributor can create a pull request whose workflow runs arbitrary code on your self-hosted infrastructure, potentially stealing credentials, planting backdoors, or exfiltrating data.
Mitigations include:
- Restrict self-hosted runners to private repositories only
- Require approval for workflow runs from outside contributors
- Run ephemeral agents that rebuild after each job
- Monitor agent resource usage for suspicious activity
- ✓Microsoft-hosted agents and GitHub-hosted runners are fully managed and ephemeral (a fresh VM per job) with no maintenance burden, but cannot reach private networks and have job time and concurrency limits
- ✓Self-hosted agents/runners can reach private/on-premises resources and pre-install specific licensed tooling, at the cost of the team owning patching, security hardening, and lifecycle management
- ✓Key decision factors between hosted and self-hosted are cost at scale, whether specific licensed tools must persist on the machine, network connectivity requirements, and who is responsible for ongoing maintenance
- ✓Azure DevOps scale set agents back a self-hosted-style agent pool with a VM scale set, combining private network reach with hosted-like elastic auto-scaling
- ✓Using self-hosted runners with public repositories is a significant security risk, since a malicious pull request from an outside contributor could execute arbitrary code on that self-hosted infrastructure; restricting self-hosted runners to private repos or requiring workflow approval mitigates this
1. A pipeline needs to deploy to an on-premises SQL Server that is only reachable from inside the corporate network, which Microsoft-hosted agents cannot reach. What is the appropriate solution?
2. What is a well-documented security risk of enabling self-hosted runners for a public GitHub repository without additional restrictions?
3. What benefit does an Azure DevOps scale set agent pool provide compared to a single, manually managed self-hosted agent VM?
Recommended: Pluralsight
This free course covers the theory. Pluralsight adds structured DevOps Engineer Expert learning paths, hands-on Azure Pipelines and GitHub Actions labs, and timed practice exams to make it stick before exam day.