Gil Allouche
← All writing
ReferenceAutonomous agents

Self-hosted AI agent platforms: what you actually control

Which layers of an agent stack you can really run yourself, what each project's license permits, and the approaches I would not use.

September 5, 2026·Gil Allouche·10 min read
A reference explainer. Every factual claim links to its source; where this is an opinion from operating experience, it says so.

The answer, and the layer most shortlists skip

n8n — the platform most people land on first when they search this — is not open source. It ships under the Sustainable Use License, which permits use for internal business purposes and restricts hosting or reselling it as a service (LICENSE.md). A self-hosted AI agent platform is an orchestration layer you run on your own infrastructure — the graph engine, the tool sandbox, the queue, the logs. The model call is still a vendor API. So the question is not which platform, but which of those four layers you are actually taking back.

Most teams take back three of four and call it self-hosted. That is a defensible choice. It is not the same as running your own stack, and the difference shows up on the invoice and in your data-flow diagram.

The four layers of a self-hosted agent platform and where the trust boundary usually falls1. Model inferenceweights, GPUs, tokensrented from a vendortrust boundary for most teams2. Orchestration and stategraph, retries, queue, logsyour infrastructure3. Tool sandboxcode, browser, filesyour infrastructure4. Credentials and egresssecrets, allowlistyour infrastructure

Layer 1 is the only one with a hard cost floor you cannot engineer away. Layers 2 through 4 are software you can run on a $40/month box until volume forces otherwise — in n8n's case that means a Postgres database for execution history and, in queue mode, a Redis instance for the job queue (scaling docs). If your reason for self-hosting is "we cannot send customer data to a third-party model provider," moving layers 2–4 in-house does not solve it. The prompts still cross the boundary. If your reason is that you need audit logs of every tool call and the retry logic in git, layers 2–4 solve it completely, and you can keep buying inference.

Name your reason before you name your platform.

The disappointing self-hosting projects are almost always teams that self-hosted the orchestrator to fix a problem living at the model layer.

What each project's license actually permits

Licenses on this list are not decoration. Three of the most-recommended self-hostable agent platforms are source-available with commercial restrictions, and the restriction is specifically the thing a software company wants to do: embed it in a product and charge for it.

ProjectLicenseWhat it means for you
n8n (Community)Sustainable Use License — source-available, not OSI-approved (LICENSE.md)Internal business use is fine. Hosting it for your customers or reselling it is restricted.
DifyDify Open Source License — Apache 2.0 plus added conditions (LICENSE)Self-host freely for your own use; multi-tenant commercial hosting and stripping Dify branding from the console are restricted.
LangGraph (library)MIT (repo)No usage restriction on the library itself. The managed platform is a separate commercial product — check pricing for which tier includes self-hosted deployment.
LettaApache-2.0 (repo)Permissive, including commercial redistribution. Agent server with persistent memory as a first-class concept, descended from the 2023 MemGPT paper out of UC Berkeley (arXiv:2310.08560).
TemporalMIT (repo)Permissive. Not an agent framework — a durable execution engine you put underneath one.
vLLMApache-2.0 (repo)Permissive inference server for open-weight models, built on the PagedAttention design published at SOSP 2023 (arXiv:2309.06180).
OllamaMIT (repo)Permissive local model runner. Fine for development, single-node by design.
OpenAI Agents SDKMIT (repo)A library, not a platform, shipped in March 2025 as the production successor to the experimental Swarm project. You supply the queue, the state, the sandbox.

Read the actual file, not a blog post about it. "Open source" in a comparison table is frequently doing the work of "you can download the code," which is a different claim — the Open Source Initiative's ten-clause definition requires no restriction on fields of endeavour, which is exactly the clause these licenses add (OSD). If you are building something you intend to sell — and if you are unclear on what that even means when the product is an agent, I wrote about the two senses of AI SaaS — a source-available core is a rebuild you have scheduled without knowing it.

The token bill does not go away

Self-hosting the orchestrator changes your hosting cost. It does not change your inference cost by a single token, because the tokens are still going to a vendor.

Price the shape first. A lead-research agent reads a company page, checks two data sources, drafts an outreach angle. Roughly 25 model turns per run. Context grows as the transcript accumulates, so call it ~12,000 input tokens per turn and ~800 output. Two thousand runs a month.

That shape is 300,000 input tokens and 20,000 output tokens per run, so 600 million input and 40 million output tokens a month. Input dominates by 15 to 1, which is why prompt caching and transcript trimming move the bill more than output limits do.

What would this cost you?
40
15,000
5,000
per run
$2.70
full pass
$13,500

Arithmetic on published list prices. Retries are billed too, so a step that fails twice before working costs three times this.

Move the model picker. That spread between the frontier model and the cheap one is the single largest cost variable in an agent system, and it dwarfs the difference between a $40 VPS and a managed control plane. It is also the argument against self-hosting weights at low volume: a GPU is a fixed cost you pay whether the agent runs or not, and 2,000 runs at 25 turns is 50,000 model calls spread over a 730-hour month — about 68 calls an hour, which leaves a dedicated accelerator idle for most of every hour.

The volume where self-hosted open weights beats per-token pricing depends on your utilisation curve, your model choice, and whether you can keep a batching server like vLLM saturated. Measure it. Do not assume it.

Where these break in production

Unbounded loops. An agent that can call itself, retry, or spawn subtasks will eventually run until something stops it — the failure OWASP catalogues as LLM10:2025 Unbounded Consumption (OWASP GenAI). The cap belongs in the orchestrator: a step cap and a wall-clock cap, enforced outside the model. For the 25-turn shape above, a 40-step ceiling and a 10-minute timeout leave normal runs untouched and stop a runaway inside one billing cycle. A model instructed to stop after ten steps is a request, not a limit. This is the first thing I would build, and it is the whole subject of your first agent, with hard caps.

Context growth. Cost per turn rises through a run as the transcript accumulates. A 40-turn agent is not four times a 10-turn agent. It is worse, because the later turns carry more input tokens. Summarise or truncate on a schedule you chose.

Prompt injection into tool calls. OWASP ranks prompt injection first — LLM01:2025 — in its Top 10 for LLM Applications and lists excessive agency at LLM06:2025, meaning an agent holding more permission than its task requires (OWASP GenAI). A self-hosted agent with a browser tool reads attacker-controlled text all day, into the same context window as your instructions.

Lost state on restart. Most agent frameworks hold run state in process memory. Redeploy mid-run and the run is gone — or worse, half-applied: the email sent, the CRM not updated. This is why a durable execution engine like Temporal keeps showing up underneath agent stacks: it persists an event-sourced history of every step and replays it after a crash or deploy (durable execution docs). Retry and checkpoint semantics are a solved problem in workflow engineering and an unsolved one in most agent frameworks.

Credential blast radius. One service account with write access to everything is how a bounded mistake becomes an unbounded one. Scope per tool.

None of these are exotic. All of them are cheaper to prevent than to debug, and the ways agentic systems break in marketing work are the same five wearing different clothes.

What I would not use

I would not build a product on a source-available core. n8n Community and Dify are good software, and both restrict hosting for third parties. If your plan involves customers running your thing, that plan contains a legal review and a migration you have not scheduled yet. Use the permissive options — LangGraph (MIT), Letta (Apache-2.0), Temporal (MIT), vLLM (Apache-2.0) — or accept that you are building internal tooling and stop pretending otherwise.

I would not run production agents on a drag-and-drop canvas. Visual builders are genuinely faster for the first version. Then you need to review a change, and there is no diff. You need to know why last Tuesday's run behaved differently, and the answer lives in a JSON blob nobody can read. You need two environments; the canvas has one. Agent logic is code. Code belongs in git, with a reviewer and a rollback. I have taken products from zero to $15M ARR and from $50K to $1.5M ARR, and the pattern held both times: the thing you cannot diff is the thing that breaks silently.

I would not self-host the model as the first move. Ollama on a laptop is the right way to develop; it is not a serving strategy. Self-host weights when you have a measured reason — data residency, a fine-tune you own, sustained utilisation high enough to beat per-token pricing — and not because it feels more self-hosted. GPU capacity planning is a full job. You already have one.

The stack I would reach for, running agents in production for the zero-human company I am building in public: permissively licensed orchestration in code, a durable execution layer under it, vendor inference at the model layer until the numbers say otherwise, and tools behind the Model Context Protocol — open-sourced by Anthropic in November 2024 — so the same tool server works against a hosted model today and a local one later (modelcontextprotocol.io).

Match the architecture to your actual reason

Your reasonWhat you self-hostWhat you can keep buying
Audit trail of every tool callOrchestration, state, logsInference
Contractual ban on third-party data processing, or GDPR Art. 28 terms you cannot get signedModel inference too — vLLM on your own hardwareNothing at the model layer
Air-gapped or offline environmentAll four layersNothing
Per-seat platform pricing is out of proportion to usageOrchestration and sandboxInference
A fine-tune on proprietary data you will not uploadModel weights and servingOrchestration, if you want
Latency floor below a network round tripModel inference, co-locatedOrchestration

The middle rows are the expensive ones. If you are in the top or bottom rows, self-hosting is a weekend of Docker Compose and a decision about where the logs go.

The sandbox is the part almost everyone under-builds

An agent that can run code needs somewhere to run it that is not your application server. A container is a start, not an answer. Shared kernel, shared risk. gVisor intercepts syscalls in a user-space kernel written in Go, so the container never talks to the host kernel directly (repo); Firecracker gives you a microVM with hardware-level isolation per run. Its specification commits to ≤ 125 ms from the InstanceStart API call to the guest’s /sbin/init, and ≤ 5 MiB of VMM memory overhead for a 1-vCPU, 128 MiB microVM — workload-dependent, and enforced by CI (SPECIFICATION.md). At any plausible rate of agent runs, that start-up cost is noise next to the model call.

Then close the network. Default-deny egress, with an allowlist per tool — specific hostnames on port 443, not a CIDR block that happens to contain the internet. This is the control that turns a prompt injection from an incident into a log line: the injected instruction to POST your environment variables to an attacker's endpoint fails at the firewall regardless of what the model decided to do. Set it at the sandbox, not in the prompt.

One more, and it is the one I would not ship without: every tool call logged with its arguments, before execution, to an append-only store the agent cannot write to. Not the model's summary of what it did. The actual call, the actual arguments, the actual response, timestamped, with a retention window you set deliberately rather than inherit. When something goes wrong at 3am on a run you did not watch, that log is the entire difference between a fix and a shrug.

Sources

  1. n8n LICENSE.md (Sustainable Use License)n8n is source-available, not OSI open source; internal business use permitted, hosting-as-a-service restricted
  2. n8n self-hosting documentationOfficial self-hosting install and configuration paths for n8n
  3. Dify documentationOfficial Dify self-hosted deployment docs
  4. LangGraph repositoryLangGraph library license (MIT) and source
  5. LangChain pricingCurrent commercial tiers for the managed platform and its self-hosted deployment option
  6. Letta repositoryApache-2.0 licensed self-hostable agent server with persistent memory
  7. Temporal repositoryMIT-licensed durable execution engine used as the retry/state layer under agents
  8. vLLM repositoryApache-2.0 inference server for self-hosting open-weight models
  9. Ollama repositoryMIT-licensed local model runner
  10. OWASP Top 10 for LLM ApplicationsPrompt injection ranked first; excessive agency listed as its own risk category
  11. Model Context ProtocolOpen protocol for tool servers you can run yourself against hosted or local models
  12. gVisorUser-space kernel used to sandbox untrusted code execution
  13. Firecracker specification (boot time and memory overhead)the document that actually states the 125 ms and 5 MiB figures
  14. OpenAI Agents SDK (Python)MIT-licensed agent library you host yourself; not a platform
  15. Dify LICENSEDify Open Source License: Apache 2.0 with added conditions on multi-tenant hosting and branding

Related