Target link: AI agents overview
Running your own AI agent sounds like the safe option. Your data stays on your infrastructure, nobody changes the terms under you, and you can read the code. All of that can be true. But an agent isn’t a passive application. It reads untrusted input, decides what to do, and acts with real credentials. Moving it in-house moves the responsibility for those actions to you as well.
This article is for technical readers who are deciding whether to host and adapt an agent system themselves. For the broader background on what agents are and how they work, see our AI agents overview.
Image 1 (hero), alt text: “Diagram of a self-hosted AI agent inside a network boundary, with arrows to a model, tools and an external web source”
What “self-hosted” actually means
The term covers several different setups, and the security picture differs for each:
- Self-hosted orchestration, hosted model. The agent loop, tools and memory run on your servers, but prompts go to a third-party model API. You control the actions, not the inference.
- Fully self-hosted. The orchestration and an open-weight model both run on your hardware. Prompts and outputs stay inside your boundary.
- Self-hosted and modified. You fork an open-source project, add tools, change prompts or patch behavior. You now own a divergent codebase.
Before you judge any of these, work out which one you are really proposing. “Our data never leaves the building” is only true for the second and third, and only if every tool and plugin also stays inside.
The open-source landscape
Searches for open-source AI agents and open source AI coding agents are growing because the appeal is practical. You can audit the code, avoid vendor lock-in, and adapt the system to your workflow. Open-source agent frameworks and coding agents vary a lot in maturity, maintenance and permission models.
Open source gives you the ability to inspect. It does not give you an inspection. Most teams never read the code of the tools they deploy, and an agent framework with hundreds of dependencies is hard to review by hand. Treat “open source” as a precondition for a security review, not as evidence that one happened.
What you gain by hosting yourself
Data locality. When the model and tools run in your environment, sensitive documents, source code and customer records don’t have to pass through a third party. For regulated data this can simplify compliance conversations, though it doesn’t replace them.
Configurable permissions. You decide which tools exist, which credentials the agent holds and which networks it can reach. A hosted product gives you whatever knobs the vendor chose to expose.
Auditability. You can log every prompt, tool call and result in the format your security team already uses.
Stability. Nobody silently swaps the model or changes defaults under you. You upgrade when you decide to.
What you take on
You own the whole attack surface. A hosted service has a security team patching its infrastructure. A self-hosted agent has you: the host, container runtime, dependencies, secrets store, network rules and the web interface you put in front of it.
Prompt injection doesn’t go away. The OWASP Top 10 for LLM Applications lists prompt injection as a leading risk (OWASP GenAI Security Project). Hosting locally doesn’t change the cause: the model can’t reliably separate instructions from data. If your agent reads a web page, an email or a repository issue, the author of that content may be able to steer the agent.
Excessive agency. OWASP also flags the problem of giving an LLM-based system too many functions, permissions or autonomy. Self-hosting makes this easier to get wrong, because it is tempting to hand a trusted internal agent broad access “since it’s ours”.
The “lethal trifecta”. Simon Willison describes a combination that makes data theft possible: access to private data, exposure to untrusted content, and a way to communicate externally (Simon Willison, “The lethal trifecta”). Many useful agents have all three by design. A useful design question is which one you can remove.
Tool and plugin supply chain. Agents extend through plugins, skills and tool servers. The Model Context Protocol specification has its own security guidance on authorization and trust (MCP specification). Every connector you install runs with some level of trust, and you are the one who vetted it, or didn’t.
Model weaknesses stay with you. With an open-weight model you choose the model, and you also inherit its safety behavior, its tool-calling reliability and its update cadence. A smaller local model may follow injected instructions more readily than a larger one, so test with your own adversarial cases and don’t assume.
Image 2, alt text: “Three overlapping circles labelled private data, untrusted content and external communication, with the overlap highlighted as high risk”
Coding agents deserve their own threat model
Open source AI coding agents are among the most searched categories, and they are the highest-privilege agents most teams will run. A coding agent typically reads your repository, runs shell commands, installs packages and edits files. That makes several risks concrete:
- Untrusted repository content. A README, a code comment, a dependency’s docs or an issue description can contain instructions aimed at the agent.
- Command execution. If the agent can run arbitrary commands on a developer laptop, a successful injection runs with that developer’s permissions and credentials.
- Secrets in reach. Environment variables, SSH keys and cloud credentials in the same session are available to anything the agent can execute.
- Package installation. An agent that adds dependencies on its own can pull in a malicious or typosquatted package.
Reasonable controls are not exotic: run the agent in a disposable container or VM, give it a scoped, short-lived token instead of your own, block outbound network access except to an allowlist, and require human approval for commands that write outside the working directory or touch the network.
A practical hardening checklist
- Isolate execution. Sandbox tool execution (container, VM or separate user), with read-only mounts where possible.
- Least privilege. One credential per agent, scoped to one job, rotated, never your personal account.
- Egress control. Default-deny outbound traffic. Exfiltration needs a channel, so close it.
- Human in the loop for irreversible actions. Payments, deletions, deployments, external messages and permission changes should need approval.
- Don’t expose the control plane. Keep the agent’s admin interface off the public internet and behind authentication.
- Pin and review dependencies. Lock versions, scan them, and review the plugins and tool servers you add.
- Log everything. Keep prompts, tool calls and outputs so incidents can be reconstructed.
- Red-team it. Test with injected instructions in the data sources your agent actually reads.
For a governance structure around these controls, the NIST AI Risk Management Framework gives a general vocabulary for mapping, measuring and managing AI risk (NIST AI RMF).
When self-hosting is the right call
Self-hosting tends to make sense when:
- the data is sensitive enough that a third-party processor is a real blocker,
- you have people who can patch, monitor and respond,
- you need custom tools or behavior a vendor will not offer,
- the agent’s permissions can be tightly scoped.
It tends to make less sense when you have no one to operate it, when the agent needs broad access and open internet exposure, or when the main motivation is an assumption that “local means safe”.
The bottom line
Self-hosting changes who holds the risk. It does not remove it. You gain control over data, permissions and change management, and you accept responsibility for sandboxing, patching, supply-chain review and monitoring. Start with the smallest useful permission set, assume the agent will eventually read something hostile, and design so that this is survivable.
To compare approaches and see how agent systems fit together, continue to our AI agents hub.
Leave a Reply