Hightower's AI Harness Engineering

Hightower's AI Harness Engineering

AgentCore II: Host a Claude Agent SDK Loop on AWS in Fifteen Lines Of Code. Then Scale your Agents on Day 1

Part 2: Bedrock AgentCore Runtime is BYOL, bring your own agentic loop. It does not care what framework you use. It’s really a bring-your-own agentic AI framework. Let's cover Claude Agent SDK

Rick Hightower's avatar
Rick Hightower
Jul 21, 2026
∙ Paid
Cover image for “Host a Claude Agent SDK Loop on AWS in Fifteen Lines. Then Read the Contract Twice.” by Rick Hightower

As you recall from our last article, the AgentCore system is from AWS, and it provides a mechanism to scale your agents in the cloud.

In this article, we cover using the Claude Agent SDK query() loop and running it from our laptop, then taking that same agent, built with the Claude Agent SDK, and hosting it on Amazon Bedrock AgentCore Runtime with a single 15-line decorator. We learn all about the runtime contract, what it promises, what it demands. How to keep the model calls inside Bedrock, and how the AgentCore CLI provides fast deployments. Then we show two things that trip beginners up: ARM64 images and synchronous handlers that will starve the health check.

There’s sort of a joy when you deploy your first agent that ran as a script, and then you deploy it into the cloud and scale it. It’s got its own endpoint. It has its own session isolation. It has a scaling story. It’s the same loop that was running on your laptop, but now it has a home in the cloud. And you get that with Bedrock AgentCore Runtime. It takes about fifteen lines of Python code to wrap your agent in a decorator. And this decorator adapts to so many different agentic frameworks. It’s really a case of bring your own agentic framework and run it in a scalable hyperscaler, and that is the core idea of AgentCore.

Those 15-lines of code provide a contract to the AgentCore system. It forces the agent to fit the shape of the AgentCore contract. It’s pretty simple, really. And then every production control is going to hang on it. The agent gets streaming, session lifecycle, multi-agent fan-out, and hardening all on that same contract. Once you understand the decorator, then you need to investigate what the contract is and understand it, and we will cover that in this series.

The only thing you have to deal with is deploying an ARM64 Docker image so you can run in an ARM64 environment, and then you’re ready to go. Otherwise, your first deploy is going to die pretty quickly. So a script becomes infrastructure in fifteen lines around a decorator. This is a real difference. Think about it. Deploy to a hyperscaler with fifteen lines of code. The lines sign a contract, and it’s a simple contract. The beauty is in the simplicity.

The loop on your laptop

Start with the agent, before any AWS is involved. The Claude Agent SDK runs the Claude agent loop inside your own Python process. One async generator, query(), handles reasoning, tool calls, permissions, hooks, sessions, and delegating tasks to subagents. You iterate it, and messages come out.

Look at how simple this market intelligence agent is. It reads a saved competitor page and summarizes what changed. This code listing shows a simple market intelligence agent that you could get up and running, and that would scale easily in AgentCore.

The SDK owns the loop. You declare tools once, consume messages, and print the final result when it arrives.

import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions

async def main():
    options = ClaudeAgentOptions(allowed_tools=[“Read”, “Bash”, “Glob”])  # ①
    async for message in query(  # ②
        prompt=”Read ./pricing-snapshot.html and summarize the pricing tiers.”,
        options=options,
    ):
        if hasattr(message, “result”):
            print(message.result)  # ③

asyncio.run(main())

① Tool access is declared once on ClaudeAgentOptions. The SDK only exposes the tools you list, and this is one way to control context bloat and control what an agent can do.

② query() is an async generator: the SDK owns the agent loop, and you only consume messages from it.

③ A final result arrives on a message that carries .result. Everything before this is intermediate traffic.

Note: The full extracted listing at code/agent-core/part-02-first-hosted-loop-claude-agent-sdk/listings/01-laptop-query-loop.py is the complete runnable program.

This is a complete agent, albeit small. This agent has an agentic loop, tools, and a stopping condition. You can run this on your local machine, using your file system, your network, your own blast radius. Of course, you’re going to first get things running on your local laptop. But how quickly can you take what’s running on your laptop, deploy it to the cloud, and scale it? And that’s where this really begins. You can deploy that same thing easily to the AWS AgentCore hyperscaler. You don’t have to do anything special. You don’t have to write any special endpoint or worry about any special session isolation. You also don’t have to worry about scaling or tracing, as the AWS AgentCore runtime will take care of this. All you have to do is implement this very small contract. This is the key idea of AgentCore: you just write fifteen lines of code, then you deploy on the back of a giant. It’s the simplicity of deployment.

Thus, you use query() to run your whole loop just as you would on your local machine; you consume messages. But when you run it locally, you don’t have a story for when forty analysts decide to use your agent all at the same time on Monday morning. This is the key selling point of AgentCore. You’re getting that scalability by deploying to AgentCore. When forty analysts hit your agent at 9 a.m. Monday morning, it’s going to work.


If you are a paid subscriber, thank you. Your support makes this work possible.

If you are a free subscriber and find these articles useful, please consider upgrading. A paid subscription is $80 per year or $8 per month.

Share Hightower's AI Harness Engineering

User's avatar

Continue reading this post for free, courtesy of Rick Hightower.

Or purchase a paid subscription.
© 2026 Rick Hightower · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture