tocOn this page 9 sections
To run an Azure DevOps self-hosted build agent on a Windows VPS, you need four things: a self-hosted agent pool in your organization, a personal access token (PAT) with the Agent Pools (Read & manage) scope, the Windows agent package unzipped on the VPS, and a run of config.cmd with --runAsService. The agent only makes outbound HTTPS connections to Azure DevOps on port 443, so you don't open any inbound ports. Your builds then run on a machine you control, using your own tools and caches.
Why build on your own VPS
Microsoft-hosted agents start from a clean image for every job. That means NuGet, npm and Docker caches are downloaded again on every run, and you can't install licensed tools that stay put. A self-hosted agent on a VPS keeps its caches between runs, can hold build tools you have licensed, and uses a fixed outbound IP that you can allowlist on databases or deployment targets. Our Windows VPS for development and testing page covers plan sizing for this kind of workload.
Prepare the VPS
Connect over RDP and open an elevated PowerShell window. Install your toolchain before you register the agent. The agent records its capabilities from the environment when the service starts, so tools installed later stay invisible until the service restarts. A typical .NET setup needs:
- Git for Windows
- Visual Studio Build Tools with the workloads your solutions use
- The .NET SDKs your projects target
- Node.js, if any front-end projects build here
Put the agent in a short path such as C:\agents\a1. Deep node_modules trees and long repo paths can exceed the 260-character limit, so enable long paths for Git as well:
git config --system core.longpaths true
Create the agent pool and token
- In Azure DevOps, go to Organization Settings > Pipelines > Agent pools > Add pool. Choose Self-hosted and name the pool, for example
VPS-Windows. Decide whether to grant access to all pipelines or authorize each pipeline the first time it runs. - Open User settings > Personal access tokens > New Token. Select only the Agent Pools (Read & manage) scope and set a short expiry. The PAT is used only to register and remove the agent. After registration the agent authenticates with its own credential, so an expired PAT does not take it offline.
Download and register the agent
In the pool, click New agent, pick the Windows tab, and download the x64 package from the browser inside your RDP session. Then extract it:
New-Item -ItemType Directory -Path C:\agents\a1 | Out-Null
$zip = Get-ChildItem "$env:USERPROFILE\Downloads\vsts-agent-win-x64-*.zip" | Select-Object -First 1
Expand-Archive -Path $zip.FullName -DestinationPath C:\agents\a1
Set-Location C:\agents\a1
Register the agent unattended as a Windows service:
.\config.cmd --unattended `
--url https://dev.azure.com/YOUR-ORG `
--auth pat --token YOUR-PAT `
--pool VPS-Windows --agent vps-a1 `
--work _work `
--runAsService `
--windowsLogonAccount "NT AUTHORITY\NETWORK SERVICE"
Check that it is running:
Get-Service vstsagent* | Format-Table Name, Status, StartType
The service is named after your organization, pool and agent, and it starts automatically. In the browser, open the pool's Agents tab. vps-a1 should show as Online.
Pick the right service account
NETWORK SERVICE is enough for most compile-and-test jobs. Switch to a dedicated local account, such as .\buildsvc with --windowsLogonPassword, in these cases:
- Builds need a full user profile.
- Builds need stored credentials.
- Builds write to a network share.
Don't give that account administrator rights unless a build step really needs them. Interactive UI tests need --runAsAutoLogon instead of a service, because the agent must run in a signed-in desktop session. Give that agent its own account so it doesn't clash with your own RDP logons.
Point a pipeline at the VPS
In your YAML file, replace the vmImage line with the pool name. You can optionally add demands so jobs only land on agents that have the tools they need:
pool:
name: VPS-Windows
demands:
- Agent.OS -equals Windows_NT
- msbuild
steps:
- checkout: self
clean: true
- script: dotnet build --configuration Release
If you install a new SDK later, run Restart-Service vstsagent* so the capability list updates. You can see what the agent reports under the agent's Capabilities tab.
More than one job at a time
Each agent runs one job at a time. For parallel builds, extract the package again into C:\agents\a2 and register it with a different --agent name. Each copy becomes its own service. Concurrent self-hosted jobs also count against your organization's self-hosted parallel job allowance, listed under Organization Settings > Parallel jobs. Before you add a third agent, watch CPU and memory in Task Manager during a real build.
Keep it healthy
- Disk:
_workgrows with every repository and artifact. Useworkspace: clean: allon jobs that don't need the incremental state, and check free space withGet-PSDrive C. - Updates: the agent updates itself when Azure DevOps requires a newer version. You don't need to reinstall it.
- Reboots: a job that is running during a Windows Update restart fails. Set active hours or a maintenance window that avoids your build times.
- Security: the agent runs any code a pipeline gives it. Restrict which projects can use the pool, and apply the basics from our Windows Server VPS hardening checklist.
To retire an agent, stop builds and run this from the agent folder:
.\config.cmd remove --auth pat --token YOUR-PAT
FAQ
Do I need to open any firewall ports for the agent?
No. The agent polls Azure DevOps over outbound HTTPS on port 443. Inbound RDP for your own administration is the only port the setup involves.
Can I run the agent on a Linux VPS instead?
Yes. Download the Linux package from the same New agent dialog, run ./config.sh, then sudo ./svc.sh install and sudo ./svc.sh start to run it as a systemd service. Use Windows when you build .NET Framework, MSBuild-only or Windows-specific projects.
What happens if the PAT expires?
Agents that are already registered keep working, because they use their own credential after setup. You only need a new PAT to register another agent or remove an existing one.
Run this on your own Windows VPS
Get a Windows VPS from WindowsVPS in about 60 seconds, with full Administrator access over RDP, NVMe storage and the Windows license included.
Written by the WindowsVPS Team
We run Windows Server VPS hosting and write these guides from the same setups our customers use: RDP, PowerShell, trading terminals and always-on bots. Questions about a guide? Contact us.