By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Standard web hosting assumes requests are independent and short-lived. Agent conversations break that assumption: they run for minutes or hours, hold private user data in memory, invoke external tools, and follow paths determined by an LLM. You need hosting designed for this behavior. AgentCore Runtime provides it through sessions and microVMs.
Each user session runs in its own dedicated microVM with isolated CPU, memory, and filesystem. User A's data cannot leak into User B's because they never share compute resources.
You identify which conversation a request belongs to by sending a session id. In the SDK this is runtimeSessionId; over HTTP it's the X-Amzn-Bedrock-AgentCore-Runtime-Session-Id header. If you omit it on the first call, Runtime generates one for you. Subsequent requests with the same id route to the same microVM, so your agent's in-memory state persists.
A session moves through three states. Active means the microVM is processing a request or running background work. Idle means it's waiting but still holding its context in memory. Terminated means the microVM is destroyed and its memory wiped.
Termination happens in three scenarios: after 15 minutes of inactivity, after the 8-hour maximum lifetime, or if Runtime judges the microVM unhealthy. Once terminated, the in-memory state is gone. If the same session id reappears, Runtime boots a fresh microVM from scratch.
Here's a concrete example. Alice sends her first message with session id 'alice-1'. Runtime boots a microVM and loads your code. She sends a second message with the same id; the same microVM answers and her variables still exist. She goes to lunch. After 15 idle minutes the microVM is destroyed. When she returns and reuses 'alice-1', a brand-new microVM starts with no trace of the old in-memory state.
Session state lives in the microVM and is ephemeral. Never use it for long-term durability. Anything that must survive—preferences, history, facts—belongs in AgentCore Memory.
This is the rule most developers miss. It's tempting to store everything in local variables and assume it will stick around. It won't. The microVM can terminate at any moment. If you need data to outlive a session, write it to AgentCore Memory, which is covered in a later lesson.
For most chat agents, the default microVM model is the right choice. But if you need a longer-lived workload, Runtime also offers an Instances compute type. Sessions there can run up to 14 days, can use persistent storage across sessions, and a single session can host multiple agents.
Platform version V2 starts your agent from a snapshot, which keeps cold starts consistent even with large container images. The trade-off is real: creating or updating a V2 runtime takes several minutes, and your /ping endpoint must report healthy within 120 seconds so the snapshot captures a fully initialized agent.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.