Sub topic 14
When to use a self-hosted or local model
This chapter assumes you know how data moves from your machine to an AI provider, and you have read the chapter on provider retention and training policies. It helps you decide when running a model on your own hardware is worth the cost.
What "local" and "self-hosted" mean
A local model runs on your own computer. A self-hosted model runs on a server you control, such as a company GPU machine or a private cloud account. In both cases the prompt is processed on infrastructure you manage, so it does not go to a third-party provider's API.
What you gain
- Less external exposure. Prompts and code do not reach a third party, so provider retention and training terms matter less.
- Control over logs. You decide what is stored, for how long, and who can read it.
- Compliance fit. Some contracts, regulations, or customer terms forbid sending certain data to outside services. A model inside your boundary can satisfy them.
- Offline use. Work continues without a network connection.
What you give up
- Model quality. Models that fit on a laptop are usually weaker than large hosted ones, especially on long, multi-file tasks.
- Operating cost. Self-hosting needs GPUs, updates, monitoring, and someone responsible for it.
- Other risks stay. Prompt injection, over-permissive agents, and secrets in source code are not fixed by moving the model. A local agent that can run shell commands is still dangerous if it reads a poisoned file.
- New risks appear. Model files come from third parties, and a local server with no authentication can be reached by other machines on the network.
A decision guide
| Situation | Reasonable choice |
|---|---|
| Open-source code, no secrets in context | Hosted tool with a plan that opts out of training |
| Proprietary code, no contractual ban on external processing | Hosted business or enterprise plan with reviewed terms |
| Regulated data or a contract that bans external processing | Self-hosted model inside your boundary |
| Unreleased security-sensitive code, small team, no GPU budget | Local model for the sensitive parts, hosted tool for the rest |
| Credentials or key material | Neither. Keep it out of any model's context |
The last row matters. A local model does not make it safe to paste a production secret. Logs, shell history, and editor caches on your machine can still leak it.
Running a local model safely
Many local runners expose an HTTP API on your machine. Bind it to the loopback address so only your own machine can connect. This example checks that a local server on Ollama's default port answers on loopback.
curl http://127.0.0.1:11434/api/tagsIf you must serve a model to a team, put it behind authentication and TLS, and restrict it by network rules. Download model files only from sources you trust, and prefer formats that cannot run code when loaded.
Mixed setups
Most teams do not choose one option. A common pattern is to classify data first, then route by class. Public and low-risk work goes to the hosted tool. Restricted code goes to the self-hosted model. Secrets go to neither. The team policy chapter turns this routing into written rules.
Exercise
Your team handles customer data under a contract that forbids sending it to outside processors. A developer proposes running a local model with a shell-enabled agent that has the production database password in its environment. Name one risk the local model solves and one it does not.
Show answer
The local model solves the contract problem, because prompts stay inside your boundary and do not reach an external processor. It does not solve the agent risk: a shell-enabled agent with a production password in its environment can still be tricked by prompt injection into exposing or misusing that password. Use scoped, short-lived credentials and agent approvals as well.