Skip to content
Mindela

By · November 20, 2026 · 8 min read

Deploying Claude Agents on Your Own Servers With the Claude Agent SDK

Claude CodeAI Agents

You can run Claude agents on your own servers by embedding the Claude Agent SDK, available for Python and TypeScript, in a service you operate and running each agent session inside a sandboxed container. One precision matters for security reviews: the agent loop, the shell and the session state live on your infrastructure, while the model is still called through the Claude API or through a cloud account you already use, such as Amazon Bedrock, Google Cloud or Microsoft Foundry.

This guide summarizes the deployment decisions in Anthropic's current documentation, as of November 2026, and adds the practical order in which to make them.

What does "deploy Claude on your own servers" actually mean?

Four different Anthropic products get conflated. Anthropic's Agent SDK overview separates them by who runs the agent:

You want toUseWho runs the loop
Embed Claude Code's agent in your own applicationAgent SDKYou, in a process you operate
Work interactively or run one-off tasks in a terminalClaude Code CLIThe developer's machine
Call the model directly and write your own tool loopClient SDKYour code
Have Anthropic host the agentManaged AgentsAnthropic, with tools in a managed or self-hosted sandbox

The Agent SDK gives you the same tools, agent loop and context management that power Claude Code, programmable in Python and TypeScript. For data-residency and security conversations, state where each component runs:

ComponentWhere it runs
Your application and the agent loopYour servers
Shell, file and search toolsYour sandbox or container
Session transcripts and memory filesYour disk or your storage adapter
Model inferenceClaude API, or Bedrock, Google Cloud or Microsoft Foundry

An agent hosted this way is an agent you operate, not a model you host. Be exact about that with your security and procurement teams.

How does the Claude Agent SDK actually run?

Hosting an agent is not like hosting a stateless API wrapper. When your code calls query(), the SDK spawns a separate claude CLI subprocess and talks to it over stdio. That subprocess owns the shell, the working directory and the session transcripts on local disk. One session maps to one subprocess, so ten concurrent sessions mean ten process trees.

Three kinds of state live on the container filesystem by default and are lost on restart, scale-down or a move to another node: session transcripts, CLAUDE.md memory files and working-directory artifacts. A SessionStore adapter mirrors transcripts to durable storage, but it does not cover memory files or artifacts, which need a mounted volume or an object-store sync.

Here is the smallest production shape, an ephemeral task container that reads its task, runs the agent with a turn limit and exits:

import { query } from "@anthropic-ai/claude-agent-sdk";

const prompt = process.env.TASK_PROMPT!;
for await (const message of query({ prompt, options: { maxTurns: 20 } })) {
  console.log(message);
}

Which session pattern fits your workload?

Anthropic documents four patterns that describe how long a container lives relative to the sessions it serves:

PatternHow it worksTypical workloads
EphemeralNew container per task, destroyed on completionBug investigation and fix, invoice and receipt extraction, document translation
Long-runningPersistent containers hosting many sessions behind an HTTP or WebSocket endpointEmail triage agents, chat bots, per-user sites
HybridEphemeral containers that restore from a SessionStore, idle between interactionsResearch that pauses and resumes, support agents that load ticket history
Multi-agent containerSeveral agent subprocesses in one container, each with its own working directoryAgents that collaborate closely or simulations

Start with ephemeral wherever the task has a clear beginning and end. It gives the cleanest isolation and the simplest cost model. Move to hybrid when users resume work over hours or days, and make the session store mandatory there, because shutting a container down without one loses the transcript.

What do you need to provision?

Runtime. Python 3.10 or later for the Python SDK, or Node.js 18.14 or later for the TypeScript SDK. Both SDKs bundle a native Claude Code binary for most installs, and that binary is pinned to the SDK version, so updating the SDK is how you update the agent. The SDK follows semver: take patch releases continuously and read the changelog before a minor.

Resources. Anthropic suggests 1 GiB of RAM, 5 GiB of disk and one CPU per agent as a starting floor for a freshly started instance. Memory grows with session length and tool activity, so measure peak memory on a representative long session, then size hosts as available RAM divided by the per-session ceiling.

Network. The SDK needs outbound HTTPS to api.anthropic.com, or to your provider's regional endpoint on Bedrock or Google Cloud. Production deployments should route outbound traffic through an egress proxy that enforces domain allowlists, injects credentials and logs requests.

Cost. The hosting guide states that token cost typically dominates container cost by an order of magnitude or more, and cites about five US cents per hour for a minimally provisioned container. Our guide to reducing LLM API costs in production applies directly here.

How do you secure an agent that can run commands?

Anthropic's secure deployment guide starts from a plain threat model: agents act dynamically, so content they process, such as a file, a web page or user input, can steer them. Claude models are designed to resist this, yet the guide recommends defense in depth. Four principles carry most of the weight:

  1. Isolate. Pick an isolation technology to match your threat model. Anthropic's comparison rates the sandbox runtime as good, with very low overhead, standard Docker containers as setup dependent, and gVisor and VMs such as Firecracker as excellent when configured correctly, with rising overhead and complexity.
  2. Least privilege. Mount only the directories the task needs, read-only where possible, drop Linux capabilities, run as a non-root user and set memory and process limits.
  3. Keep credentials outside the boundary. Run a proxy that injects keys into outbound requests so the agent can make the call but never sees the secret.
  4. Control the network. Restrict egress to specific endpoints through a proxy, and apply per-tenant egress rules in multi-tenant systems.

For shared containers that serve several tenants, the default behavior of reading settings and memory files from the filesystem can leak one tenant's context into another's session. The documented controls are an empty settingSources, disabling auto memory, a per-tenant CLAUDE_CONFIG_DIR, a per-tenant working directory passed as cwd, and per-tenant egress policy.

How do you authenticate and use your own cloud account?

The subprocess reads ANTHROPIC_API_KEY from its environment, which you should supply from a secret manager. Better, set ANTHROPIC_BASE_URL to a proxy that injects the key outside the container. For teams that already buy Claude through a hyperscaler, the SDK supports provider authentication through environment variables:

  • Amazon Bedrock: CLAUDE_CODE_USE_BEDROCK=1 plus AWS credentials.
  • Google Cloud (Agent Platform, formerly Vertex AI): CLAUDE_CODE_USE_VERTEX=1 plus Google Cloud credentials.
  • Microsoft Foundry: CLAUDE_CODE_USE_FOUNDRY=1 plus Azure credentials.

This is often the deciding factor for regulated buyers, because model traffic then follows existing cloud contracts, regions, IAM roles and audit logs. Put authentication for inbound users at a gateway in front of the container, so the agent receives pre-authenticated requests and never validates user tokens itself.

What is the production checklist?

  1. Pick the session pattern per workload: ephemeral, long-running, hybrid or multi-agent.
  2. Run every session inside a sandboxed container or VM, sized from measured memory.
  3. Attach a SessionStore wherever users resume sessions, and alert on mirror_error messages.
  4. Route egress through a proxy with a domain allowlist and request logging.
  5. Keep API keys and tool credentials outside the agent environment.
  6. Set maxTurns on every agent and subagent, and enforce a spend limit.
  7. Export OpenTelemetry traces, metrics and logs to your collector so you can see which tools ran and where sessions stalled.
  8. Isolate tenants with per-tenant config, working directories and egress policy.
  9. Pin the SDK version, review changelogs and test upgrades.
  10. Require human approval for irreversible actions and test the agent against representative tasks before rollout.

What limitations should you plan around?

The hosting guide lists several. There is no top-level session timeout, so bound work with maxTurns. Memory grows over long sessions, so cap session length or recycle subprocesses. Large parallel subagent fan-outs can hit rate limits, so batch work. There is no per-subagent wall-clock deadline, so cap each subagent's turns. These are manageable, but only if they are in the design before launch.

When should you choose Managed Agents instead?

If you do not need to run the agent loop on your own infrastructure, Managed Agents lets Anthropic host the loop while tools run in a managed sandbox or a sandbox you host. The trade is less operational burden for less control over where the loop executes. Decide by asking which team will carry the pager, and what your security review requires to stay inside your boundary.

How this fits enterprise training and delivery

Deploying an agent is an engineering project with a security review attached, not a weekend script. In our one-week J.P. Morgan program, teams covered the Claude Agent SDK as a way to deploy Claude on the firm's own servers, next to test-driven development and spec-driven development. If you want an agent built and reviewed against your environment, our Claude Agent SDK development service covers architecture, sandboxing and rollout. For background on what makes a system agentic in the first place, read what agentic AI is.

Tell us what you plan to deploy and where it has to run, and we will scope the safest path.

Frequently asked

Can I run Claude on my own servers?

You can run the agent on your own servers with the Claude Agent SDK, meaning the agent loop, the shell and file tools, and the session state. The model itself is not hosted by you: requests go to the Claude API or to a cloud provider you already use, such as Amazon Bedrock, Google Cloud or Microsoft Foundry.

What is the difference between the Claude Agent SDK and Managed Agents?

With the Agent SDK you run the agent loop in a process you operate. With Managed Agents, Anthropic hosts the loop, and tool execution runs in an Anthropic-managed sandbox or a self-hosted sandbox on your infrastructure. Choose the SDK for maximum control and Managed Agents when you do not want to operate the loop.

Do I need Docker or Kubernetes to deploy the Claude Agent SDK?

The SDK does not require them, but Anthropic's hosting guidance recommends running agents in sandboxed containers for process isolation, resource limits and network control. Docker, Kubernetes and sandbox providers are the documented deployment targets, and the sandbox runtime offers lighter isolation for simpler cases.

How much does it cost to host Claude agents?

Anthropic's hosting guide says token cost typically exceeds container cost by an order of magnitude or more, and cites roughly five US cents per hour for a minimally provisioned container. Budget for tokens first, and cap runaway sessions with turn limits and spend controls.

Is it safe to let an agent run commands in production?

Only inside a boundary you control. Agents can be misled by content they process, so use container isolation, a read-only filesystem where possible, an egress proxy with a domain allowlist, credentials injected outside the agent environment, and human approval for irreversible actions.

Working through this decision yourself?

We’re happy to pressure-test your thinking. Engineering opinions, no sales sequence.

Talk to an engineer