SSD Nodes Learn Hosting plans →
How to do am Matt ConnorBy Matt Connor

How to Build Claude AI Agent for VPS

Learn how Claude Messages API, tool use, and MCP fit together, so your VPS can run an AI agent you control without hosting the model yourself.

Wetin building an agent with Claude mean

Building an agent with Claude mean say you dey use Claude as the reasoning core, while the loop, tools, and data dey for your own server. Claude go decide wetin to do; your VPS go carry am out. You go send the task and current state give Claude. Claude go reply with either answer or request to use one of your tools. Your code go run the tool and send the result back. The loop go continue until the job finish. The intelligence na service wey you dey call through internet. Everything around am na your own.

Na this separation make the setup useful. You get frontier-level reasoning without operating a model, and you keep full control of wetin the agent fit access, because the tools dey run for hardware wey you own. If you don already build your first Claude program, the guide for first Claude app on a VPS dey cover the groundwork wey this one dey build on.

Claude na the brain: the Messages API

Every call to Claude dey pass through one endpoint, the Messages API. You go send the conversation wey don happen and the list of tools wey the agent fit use; Claude go send back the next message. That message fit be final answer or request to call a tool. For the build-it-yourself path, no separate "agent API" dey: tool use na feature of this single endpoint, and na you go run the loop around am.

Claude no dey keep state between calls, so e no remember anything by itself. Every request carry the complete conversation. Your code hold the history and send am for every turn, and na why each turn for long session dey cost more tokens pass the previous one. This no really be limitation; na design choice. Because your server hold the state, na you decide exactly wetin Claude go see, and nothing about the task dey stored for anywhere wey you no control. But e mean say the prompt dey grow continuously. Claude's context window fit handle this without wahala, but local model for the same loop no fit. Na why Ollama need make you raise num_ctx before e stop truncating long prompts.

Tool use na agent loop

Agent loop wey use Claude no hard to explain. You go send request wey include your tools. Claude go read the task and, if e need act, e go reply with tool-use request wey name one tool and fill the inputs. Your code go run that tool, then send the result back to Claude for the next request. Claude go read the result and either ask for another tool or write the final reply. Once e stop asking for tools, the task don finish.

You fit write that loop by hand with just few lines, and plenty people dey do am because e easy to see and control. The official SDKs also get tool runner wey dey drive the loop for you: you provide the tool functions, and the SDK handle the back-and-forth of calling Claude, running your tools, and sending the results back until Claude finish. Either way, the structure remain the same. The runner only save you from writing the loop yourself. If the loop still dey look abstract, write one minimal loop before you use runner. Na this step everything else depend on for this staged path for learning AI agents from scratch.

Ways three dey to build am, and which one fit VPS

Ways three dey to build Claude agent, and dem differ based on how much of the machinery you go run.

The first one na your own code wey dey call Claude API with your own tools. You write the loop, or use the SDK's tool runner, then host everything for your VPS. Na common choice be this because e give you complete control over the tools, data, and security. E dey run like ordinary program for your server. Most of this guide dey assume say na this path you choose.

The second one na Claude Agent SDK. Na Claude Code, the coding agent, packaged as library wey you fit build on. E come with complete agent loop and built-in tools for reading and writing files, running shell commands, and searching. So you no need assemble those things from scratch. E still dey run for your own server, so e fit VPS well when you want capable file-and-shell agent without building the harness yourself. Agent wey dey read files and run shell commands need containment before e fit work unattended. Run Claude Code safely for server explain the permission system, sandbox, and isolation options.

The third one na Managed Agents, where Anthropic dey run the loop. By default, the agent tools dey execute for sandbox wey Anthropic host, so the agent workspace dey for Anthropic infrastructure instead of your VPS. As of October 11, 2026, self-hosted sandbox option wey still dey beta allow worker process for your own server to run the tool calls, while the loop remain with Anthropic. Use Managed Agents when you want the least operational work and you no need the loop itself to run for your own machine. For the other two, na your server be the home of the complete agent, and na that the rest of this guide dey cover.

Tools connect with MCP

Any path wey you choose, you go want connect the agent to real systems, and Model Context Protocol na the neat way to do am. MCP na open standard for exposing tools and data to an agent. Instead make you write integration code by hand for every service, you point Claude to MCP server wey already presents those capabilities as tools. You fit run MCP servers as small services for the same VPS, with each one getting only the access wey e need. I explain this for how to run MCP servers for a VPS.

Model wyb

Claude dey come for different models, and to choose one na trade-off between capability, speed, and cost. As of October 11, 2026, current lineup na Claude Opus 5.5 (claude-opus-5-5), wey Anthropic recommend as starting point for most workloads and wey dem build for long-running agentic coding and knowledge work; Claude Sonnet 5.5 (claude-sonnet-5-5), na balanced option wey cheaper and quicker; and Claude Haiku 5.5 (claude-haiku-5-5), wey fastest and cheapest, for simple, high-volume steps. Above dem dey Claude Fable 5.1 (claude-fable-5-1), wey be the most capable model open to all customers, for demanding reasoning and long-horizon agentic work. Older models like Claude Opus 4.8 and Claude Fable 5 still dey available, but dem don list dem now as legacy. Use the exact model identifier for your code, without adding date.

Practical pattern na to mix dem. Make cheaper model handle routine tool calls, while stronger one handle hard decisions. Because model na just string inside your request, switching am na one-line change. So start with capable default, then reduce am where speed or cost matter pass the last small improvement for quality.

Run am as hardened service for your VPS

Agent go only useful if e remain dey run, and e go only safe if you contain am. For VPS, you fit get both by running agent as hardened system service instead of program wey you start by hand for terminal. As service, e go start when system boot, e go restart if e crash, and e go write logs to journal. When e hardened, e go run as unprivileged user with only the access wey e need, so bug or bad instruction no go get unlimited reach. Service unit fit limit wetin process fit touch, and how much memory, CPU, plus how many tasks e fit use. But e no fit judge wetin agent decide to do with that access. Na why the remaining controls suppose dey inside agent harness itself. This na the work wey the DeepSeek Harness plugins wey worth installing dey do for another stack: spend caps, per-tool permission rules, and prompt-injection scanning.

The most important rule na to keep your Claude API key for server side. The key dey pay for and authorise every call, so e suppose dey inside file wey na only agent user fit read. Load am into service as environment variable. Never put am for code, repository, or anywhere browser fit reach. Generate complete, hardened service unit for your agent here:

ToolRun your agent as a hardened service

Then secure the server itself. Make SSH use keys only, and lock down the account wey you dey administer from, as e dey for SSH hardening for a VPS. If you prefer to control agent from interactive session while you dey build am, running Claude Code for a VPS with tmux na good companion. Once you open second session for the same box, the two fit pass work between themselves instead of you carrying every instruction from one pane go the other. And if you want understand the ideas behind all this without tying dem to one model, the sister guide on building your own AI agent for a VPS explain the foundations.

If na terminal coding assistant you want, running a coding AI agent for a VPS cover Aider and Goose.

FAQ

Which Claude model I suppose use to build an agent?

Start with Claude Opus 5.5 (claude-opus-5-5), wey Anthropic recommend for most workloads, then adjust from there. Claude Sonnet 5.5 (claude-sonnet-5-5) cheaper and faster for most work, Claude Haiku 5.5 (claude-haiku-5-5) best for simple high-volume steps, and Claude Fable 5.1 (claude-fable-5-1) get the highest capability for the hardest tasks. Common pattern na to use cheaper model for routine steps and stronger one for hard decisions, because switching na one-line change.

I go run the whole agent for my VPS, or Anthropic go run am?

E depend on the approach. If you write your own loop against the Claude API, or use the Claude Agent SDK, the agent go run entirely for your VPS and na only the model calls go Anthropic. If you use Managed Agents, Anthropic go run the loop and by default host the sandbox where tools dey execute, so less part of am dey your server; self-hosted sandbox option, wey dey beta as of October 11, 2026, move tool execution go your own machine while the loop remain with Anthropic. If you want agent wey go run entirely for your own machine, use one of the first two options.

Wetin be the difference between Claude API and Claude Agent SDK?

Claude API na the raw Messages endpoint: you send conversation and tools, then write the agent loop around am, or use the SDK tool runner to drive am. Claude Agent SDK na higher-level library, Claude Code packaged for building on, wey ship with full loop and built-in file, shell, and search tools. Use API when you want define everything yourself, and use Agent SDK when you want capable agent without assembling the harness.

How I go keep my Claude API key safe for server?

Keep am for server side and comot am from your code. Store am inside file wey only the account wey agent dey run as fit read, load am into the service as environment variable, and never commit am to repository or expose am to browser. Because every request to Claude dey come from your server, the key no need reach user's device, and na this make server-run agent easier to secure than agent wey dey embedded inside client app.

I need self-host model to build agent with Claude?

No. With Claude, the model na hosted service wey you call through API, so nothing dey run for GPU. Your VPS dey run the agent loop, tools, and data, while reasoning dey happen for Anthropic side. Na this allow modest server run capable agent. If you want fully local model instead, na the self-hosted path wey companion guide on building your own AI agent cover.