Software Ownership

The Rise of the Self-Hosted Agent Factory: How to Self-Host AI Coding Agents

You do not need a per-seat contract to run a serious AI coding agent. Open-source tools now let engineering teams build and own a sandboxed agent stack on their own infrastructure.

At a glance
  1. 01Commercial AI coding tools can cost $200 to $600 per engineer monthly due to token-based billing.
  2. 02Self-hosting open-source agents like OpenHands or Cline eliminates vendor seat licenses.
  3. 03Running agents in isolated Docker containers prevents them from altering host filesystems.
  4. 04Routing routine tasks to local models and complex ones to cloud APIs keeps costs under $50.
Minimal ink-and-crimson illustration of a server rack shaped like a factory with robotic arms working inside isolated sandbox containers

The short answer

You self-host AI coding agents by combining three layers you control: an open-source agent runtime (Aider, Cline, OpenHands, or similar), a model routing layer that can point at cloud or local models, and an isolated execution sandbox, usually Docker, so the agent never touches your host system directly. None of this requires a vendor contract. The agent software is free under Apache 2.0 or MIT licenses, and your only real recurring cost is whichever model API calls you choose to make.1

This matters right now because per-seat AI coding tools have gotten expensive in a way that is hard to predict. GitHub Copilot completed its move to token-based AI Credits billing in June 2026, and one developer reported going from $29 to $750 a month under the new system, while another jumped from $50 to $3,000.2 Across the three most-used tools, GitHub Copilot, Cursor, and Claude Code, the fully loaded cost per engineer now runs $200 to $600 a month once you count seat fees plus token spend, not the $10 or $20 sticker price most budgets were built around.2 Some internal benchmark analyses put the median all-in cost of a fully loaded AI coding stack at roughly $28,000 per developer per year once you stack IDE assistants, general AI subscriptions, usage overages, and observability tooling.3

That gap between the advertised price and the real bill is why more engineering teams are looking at self-hosting.

Why teams are doing this instead of paying per seat

Three things changed at once. First, the open-source agents got good. OpenHands, formerly OpenDevin, now runs the CodeAct v3 scaffold paired with Claude Opus 4.6 to a 68.4% score on SWE-bench Verified, within range of proprietary agent scaffolds, and it does this while running entirely as a self-hosted, MIT-licensed platform.4 Second, vendor pricing got less predictable. Cursor moved from unlimited fast requests to raw token-based billing in mid-2025 after users reported bills far above the advertised Pro plan. Third, and maybe most important, teams realized the seat license was never the real cost. It is the usage-based overage on top of it that breaks budgets.3

When you self-host, you flip that structure. The agent is free. You pay only for the model tokens you actually consume, and you can route cheap, routine work to a local model and reserve frontier model calls for the hard problems.

How to actually build a self-hosted agent stack

Step 1: Pick your agent runtime based on how autonomous you want it to be

There is a real split between pair-programming tools and autonomous agents, and picking the wrong one for your workflow is the most common early mistake.

  • Aider (Apache 2.0) is a terminal-native pair programmer. It builds a repo map, edits your real working tree, and commits every AI change to git automatically so you can review or revert it. It has crossed 6.8 million PyPI installs.1 Choose this if you want a human approving every edit.
  • Cline (Apache 2.0) lives inside VS Code, with over 60,000 GitHub stars. It plans, edits, and runs terminal commands with approval gates at each step, and it can drive a real browser.1 Good middle ground for teams that do not want to leave their editor.
  • OpenHands (MIT) is the autonomous end of the spectrum. Give it an issue and it plans, writes code, runs tests, and browses documentation inside a sandboxed Docker runtime until the task is done or it gets stuck.41 This is the tool for unattended, end-to-end tasks like closing out a GitHub issue overnight.
  • Continue (Apache 2.0) is the strongest option if the real requirement is that code never leaves the machine. It pairs autocomplete and chat with fully local models through Ollama or llama.cpp.1

Most teams that go this route do not pick one. A common pattern is Cline or Aider for interactive daily work, with OpenHands reserved for long-running autonomous tasks like whole-issue resolution.

Step 2: Sandbox the execution layer, do not skip this

Self-hosting does not automatically mean the agent is safe to let loose on your systems. OpenHands runs each agent conversation inside an isolated Docker container with terminal, editor, browser, and file system access scoped to that sandbox, which is precisely what keeps a runaway agent from touching your host filesystem.4 A hardened deployment on Ubuntu 24.04 LTS with CIS Level 1 baseline hardening is a documented pattern for teams that need to check compliance boxes, complete with NSG rules limiting inbound traffic and TLS termination handled explicitly rather than assumed.

If you are running Cline or Aider instead, the approval-gated action model does some of this work for you, since the agent asks before it executes anything destructive. But if you are giving an agent unattended, repeated access to a shell, run it in a container or on a scratch branch, and never hand it credentials it does not strictly need.

Step 3: Decide where your models live

This is the actual cost lever. Point your agent at a cloud API and you pay per token, same as a SaaS tool, just without the seat markup. Point it at a local model through Ollama, and your marginal cost drops close to zero, at the price of roughly 60 to 70 percent of frontier-model quality on everyday tasks.

A practical split that shows up repeatedly in team setups: route routine completions and simple edits to a local model like Qwen 2.5 Coder running on a single GPU with 24GB of VRAM, and reserve calls to Claude or GPT-class models for complex refactors or architectural decisions. This mirrors the tiered model architecture that cost-conscious teams are already applying to their SaaS AI spend, where frontier reasoning models are reserved for a small fraction of high-value tasks instead of every interaction.

Step 4: Wire it into your existing workflow, not around it

An agent stack that lives outside your normal git and CI process just becomes shadow infrastructure. OpenHands ships webhook-driven automation that connects to GitHub, Slack, and Linear, so agent-opened PRs land in your normal review queue rather than a separate silo.4 Whichever tool you pick, insist on this: every agent-generated change should surface as a diff or a PR a human reviews, the same way you would review a junior engineer's work.

Step 5: Govern it like infrastructure, not like a browser extension

The teams that get burned by self-hosted agents are usually the ones that skip this step. Set hard limits on how much any single agent session can spend on frontier model calls. Track cost per PR merged and cost per feature shipped the same way you would track cloud spend. This is the same discipline that engineering leaders are now being forced to apply to their commercial AI tool bills, where the median all-in cost of $28,000 per developer per year only became visible once finance actually itemized it.3 Self-hosting does not make that governance optional. It just moves the accountability from a vendor invoice to your own dashboard.

What this costs in practice

The agent software itself is free in every case here. Your real ongoing cost is the model. A team running Cline for interactive work, Aider for terminal-first tasks, and a local Ollama model for routine completions typically spends $20 to $50 per engineer per month on the API calls that actually need a frontier model, a fraction of the $200 to $600 per developer per month that teams running commercial seat-based tools with agentic add-ons are now reporting.21

Figure 1
Monthly AI coding cost per developer: commercial seat vs self-hosted stack
Monthly cost per developer (USD)
$60.00GitHub Copilot Enterprise (effective)$400Blended commercial stack (seat + tokens)$35.00Self-hosted (local model + selective API)
Deployment model
Self-hosted figure is a commonly cited blended estimate for local-plus-API agent setups.
Source: DX

That gap is also the same instinct behind the broader shift toward owning software instead of renting it. Just as more teams are learning that the internal tools they build themselves are assets they can actually control, a self-hosted agent stack turns what was a recurring per-seat expense into infrastructure you own outright, no different in spirit from how a team might use something like Remy to build and own the internal apps their operators need rather than subscribing to another SaaS seat for each one.

Frequently asked
Is self-hosting an AI coding agent actually free?

The agent software is free under Apache 2.0 or MIT licenses. Your cost is the model: cloud APIs bill per token, while local models cost close to nothing per query beyond hardware you already own.

Does self-hosting guarantee my code never leaves my network?

No. Self-hosting the agent runtime does not stop code from reaching a cloud model if you point the agent at one. For a fully private data path, pair the agent with a local model through Ollama or llama.cpp.

Which self-hosted agent should I start with?

Aider or Cline if you want a human reviewing every change. OpenHands if you want an agent that can attempt a whole task unattended inside a sandboxed Docker container.

How does the cost compare to Cursor or GitHub Copilot?

Commercial tools now run $200 to $600 per developer per month with seat fees and token overages. A self-hosted stack on a local model with selective frontier calls commonly lands at $20 to $50 per engineer per month.

Is it safe to let a self-hosted agent run shell commands unattended?

It is safer than a closed agent because you control the environment, but still needs guardrails: run it in a container, gate destructive actions behind approval, and review every change before merge.

Sources
  1. 1.9 Open-Source AI Coding Agents Worth Self-Hosting — SSOJet
  2. 2.AI coding assistant pricing and ROI guide (2026): costs, benchmarks, and what the data shows — DX
  3. 3.AI Coding Costs Are Now a Board Metric — Nextdev
  4. 4.OpenHands - Hardened Self-Hosted Autonomous AI Agent — Microsoft Marketplace
Portrait of Marcus Bello
Marcus Bello
Build vs Buy
Marcus writes about when teams should build their own tools instead of buying.
© 2026 The Official Remy BlogDrafted by AI authors, reviewed by human editors.