AWS Builder Center
Where Should Claude Code Actually Run? Lambda MicroVMs vs. AgentCore Runtime vs. a Box of Your Own

Where Should Claude Code Actually Run? Lambda MicroVMs vs. AgentCore Runtime vs. a Box of Your Own

Your coding agent has a shell, your credentials, and it dies when you close the lid. Here are three ways to run Claude Code in an isolated AWS environment that keeps working after you walk away, and how to pick between them.

The agent on your laptop is a liability

Most of us meet Claude Code the same way: installed locally, running in a terminal, editing files in the repo we already have open. That works until it doesn't.
Two things eventually push the work off the laptop. The first is security. A coding agent has a shell, a filesystem, and an inbox for instructions you don't fully control. On your machine it runs with your permissions, your AWS credentials, and your SSH keys, so anything it does, it does as you. The second is availability. Local sessions end when you close the lid. If you want an agent to keep refactoring a service, run an overnight migration, or pick up a task while your machine is asleep, it needs to live somewhere that stays awake.
So the real question isn't "how do I run Claude Code," it's "where does it run, and what can it touch." That's an architecture decision, and it splits along a line worth naming up front:
  • Interactive work - you attach to a long-lived session, type, watch, detach, and come back later. This is the CLI experience you already know, moved to a box that stays on.
  • Programmatic work - a task fires (a pull request, a schedule, a webhook), an environment spins up, the agent does the job, and the environment goes away. This is closer to hosting an agent than using a CLI.
This post is mostly about the first case, running the Claude Code CLI remotely, with notes on the second where it changes the answer. We'll look at three options on AWS:  AWS Lambda MicroVMs ,  Amazon Bedrock AgentCore  Runtime, and a virtual machine you run yourself on  Amazon Lightsail  or  Amazon Elastic Compute Cloud (Amazon EC2) .

What you're actually choosing between

Before comparing products, it helps to know the axes you're comparing them on. Six of them decide most of the outcome:
  • Isolation - how strong is the wall around the environment? Can code inside break out and reach the host or another tenant? A shared container is a namespace; a microVM or full VM is a hardware-backed boundary with its own kernel.
  • Permission scope - separate from isolation: how tightly can you limit what the agent is allowed to reach in your AWS account? This is an identity question (which key, which bucket, which API), not a containment one.
  • Persistence - does the environment keep its filesystem and state between sessions, or start fresh every time?
  • Live session - can you attach an interactive shell and drive it live, or do you only invoke it through an API?
  • Container capability - can the agent run containers of its own (for example, to build and run an image or spin up test containers)?
  • Cost and operations - what do you pay for and while it's idle, and how much do you run yourself?
Two of these decide the answer more often than the rest, so they're worth dwelling on before we get to specific services.
Whether you can attach to a live session is what separates a remote environment from a fire-and-forget job. For the interactive CLI workflow, you want to open a session, work in it, disconnect, and reconnect later to find it exactly as you left it, all without your own machine staying awake. Some environments are built for that and hold their state across a disconnect; others are designed to run a task and tear down, and bolting an interactive experience onto them is swimming upstream. If "close my laptop and pick up where I left off" is the point, this axis is the one to check first.
Whether the agent can run containers of its own is a hard requirement for a whole class of coding work, and it's binary: either the environment lets you build and run container images inside it or it doesn't. Plenty of real tasks need it, running a containerized test suite, building an image to check it, standing up a dependency to test against. If your work touches any of that, an environment that can't run containers isn't a compromise, it's a non-starter, and this alone can decide the choice.
Keep these in mind as we go. The recommendation at the end maps back to them.

How they actually work (the short version)

Lambda MicroVMs are a compute primitive in  AWS Lambda . Each one is a virtual machine with its own kernel, built for running code that a user or a model generated. You package an image, and Lambda launches an isolated VM from a snapshot in sub-second to single-digit-second time. You drive its lifecycle yourself: run, suspend, resume, terminate. It runs for up to eight hours and can be suspended and resumed with its memory and disk intact, billed per second only while it's active. It's a general primitive, so you map one MicroVM to a session, a job, or a sandbox, whatever fits.
AgentCore Runtime is the hosting layer of Amazon Bedrock AgentCore. It gives every session its own dedicated microVM with isolated compute, memory, and filesystem, then terminates it and wipes the filesystem when the session ends. It's framework-agnostic and model-agnostic, so it can host the Claude Code CLI, the Claude Agent SDK, or an agent you built on another framework, and you deploy either a container image or (for Python) a code package.
A box of your own is the classic answer: an Amazon Lightsail instance or an Amazon EC2 instance running Linux, with Claude Code installed, that you reach over SSH. It's the most familiar model and the one you have the most control over, at the cost of running and securing the machine yourself. Lightsail is the simpler, fixed-price front door to the same idea; EC2 is the fuller-control version.

Option 1: Lambda MicroVMs

Lambda MicroVMs are purpose-built for running code you don't fully trust, one isolated environment per user or session, without managing any virtualization yourself.
Pros
  • Strong isolation. Each MicroVM is a separate VM with its own kernel, so nothing is shared between them and you can run untrusted code safely.
  • Fast to start and cheap at rest. Snapshot-based launch that can be sub-second, and suspend/resume that preserves memory and disk. You pay per second while running and only snapshot storage while suspended, so idle time isn't charged as compute.
  • Lifecycle control by design. You call run, suspend, resume, and terminate, and map a MicroVM to whatever unit fits your workload (a session, a job, a sandbox).
  • A first-class interactive shell. Launch the MicroVM with the  SHELL_INGRESS  network connector, generate a shell auth token, and connect from the AWS console or a WebSocket client to run  claude  directly in the VM. Each MicroVM also has its own HTTPS endpoint speaking HTTP/2, WebSockets, and gRPC for anything programmatic.
  • Runs containers of its own. Elevated Linux capabilities on a single toggle ( additionalOsCapabilities: ["ALL"] ) run containerd inside the VM, so the agent can build an image from a Dockerfile, run it, and bring up test containers, all inside the VM's isolation boundary.
  • A natural fit for the self-hosted sandbox model, where the model and agent loop run elsewhere and your MicroVM runs the tool calls inside your own account, with the isolation and lifecycle control that implies.
Cons
  • Lower-level than a managed agent host. There are no servers or load balancers to manage, but you decide how MicroVMs map to your work and stitch the pieces together (image, connectors, lifecycle) yourself.
  • Hard limits to design around: eight-hour maximum lifetime, up to 8 GB memory and 4 vCPU baseline bursting to 32 GB and 16 vCPU peak, up to 32 GB disk, and ARM64 only.
Best when you're running per-task or per-session agent work, especially untrusted or model-generated code, and you want VM-grade isolation with serverless economics and control over the lifecycle.

Option 2: Amazon Bedrock AgentCore Runtime

AgentCore Runtime is a managed home for agents. It handles the isolated compute and lifecycle so you can focus on the agent rather than the infrastructure.
Pros
  • Managed isolation with clean teardown. Every session gets a dedicated microVM, and the whole thing is terminated and its filesystem wiped when the session ends.
  • A real answer for long, resumable work. Sessions are ephemeral by default, but managed session storage (preview) keeps a per-session filesystem across stop/resume for up to 14 days idle, and  InvokeAgentRuntimeCommand  lets you run shell commands inside the live session and stream results back over HTTP/2.
  • Framework- and model-agnostic. It hosts the Claude Code CLI or the Claude Agent SDK, and deployment is either a container image or a Python code package, so there's no cluster to run.
  • It composes with the rest of the AgentCore family (Gateway for tools, Identity for auth, Observability for tracing) if you later want those, though those are separate services, not Runtime itself.
Cons
  • No container-in-container. A container image is how you ship the agent (capped at 2 GB), but there's no way to run containers inside a session, so build-and-run-an-image workflows are out. This alone can rule Runtime out.
  • Modest per-session ceiling. You don't pick a size (compute is consumption-based), but a session tops out at 2 vCPU and 8 GB, with an eight-hour cap.
  • Small persistent workspace. Managed session storage caps at 1 GB per session, and it's a hard limit (not adjustable). A repo plus its dependencies and build artifacts can exceed that.
  • The execution role's permissions apply to everything the runtime does and can't be narrowed per invocation at the config level. For finer control, the agent assumes a more restricted role at runtime.
Best when you want a managed place to host a coding agent for interactive or long-running work, you value session isolation and clean lifecycle over raw control, and your tasks don't need to run containers of their own.

Option 3: Lightsail or EC2 (the box you own)

Sometimes the right answer is the oldest one: a Linux machine that stays on, with Claude Code installed, that you connect to and drive.
Pros
  • Total control and zero surprises. Your kernel, your packages, your Docker, your uptime. Containers, image builds, and long-lived  tmux  sessions all work natively, with nothing to enable first.
  • The most natural interactive experience. On EC2, connect with  AWS Systems Manager  Session Manager rather than opening port 22 (no inbound ports, no bastion, IAM-based access and logging); Lightsail offers a browser-based SSH client. Pair either with  tmux  or  mosh  for attach/detach sessions that survive disconnects.
  • Predictable cost on Lightsail. Fixed monthly instance pricing makes budgeting simple, which is easier to reason about than usage-based billing when the box is meant to stay on.
Cons
  • You own the security and the operations: patching, network configuration, and making sure the box isn't left reachable when it shouldn't be.
  • An always-on box costs money whether or not it's doing anything, so idle time is wasted spend unless you stop it.
  • Isolation is only at the VM level. Anything finer, like sandboxing individual tools inside the box, is application-layer work you add yourself; the VM boundary is the same on Lightsail and EC2. And that finer sandboxing trades off against capability, since the tighter you lock a tool down, the more likely it is to stop working.
Best when you want an always-on environment you fully control, you need native container support, and you're comfortable owning the machine and its security. Lightsail if you want it simple and fixed-price; EC2 if you need more control or scale.

Also worth knowing

A few options sit just outside the main three:
  • Dev containers and Docker are the isolation primitive underneath several of these options, and running Claude Code inside one on any host is a solid local-and-portable choice. It's container-level isolation, not a VM boundary.
  • Claude Code on the web is the zero-setup option, but it's hosted by Anthropic rather than in your AWS account, so it doesn't meet the "runs inside my security boundary" requirement that motivated this post. Worth knowing it exists; not the tool for this job.

Drawing the security boundary

Wherever the agent runs, the point of moving it off your laptop is to control what it can reach. Two ideas do most of the work here.
Isolation is not permission. A microVM or VM stops code from escaping its environment. It does nothing to stop the agent from calling an AWS API it shouldn't. Those are separate boundaries, and you need both. The isolation keeps the environment contained; the identity keeps its reach in check.
Scope the identity to the exact resources. All three options run under an  AWS Identity and Access Management (IAM)  role, and IAM is where you draw the line on what the agent can touch:
  • Lambda MicroVMs assume an execution role you set at launch, delivered inside the VM through the instance metadata service. Scope it to exactly what the task needs, for example read of a single secret and nothing else.
  • AgentCore Runtime uses an execution role too. Because that role applies to everything the runtime does, the pattern for finer control is to have the agent assume a more restricted, session-scoped role for a given task.
  • A box uses an instance profile, the same IAM idea, with the caveat that a long-lived machine means a longer-lived set of permissions to keep tight.
In practice, scope the role to specific resource ARNs rather than wildcards: a single  AWS Key Management Service (AWS KMS)  key for the one  kms:Decrypt  the agent needs, a specific  Amazon Simple Storage Service (Amazon S3)  bucket, prefix, or object rather than  s3:*  on everything. Add network boundaries on top: reach private data through VPC endpoints, restrict egress to the destinations the agent actually needs, and make sure long-lived keys never live inside the environment when a scoped role can do the job.

So which should you pick?

Line the options up against the axes and the choice usually makes itself.

Lambda MicroVMs
AgentCore Runtime
Lightsail / EC2
Isolation
microVM, own kernel
microVM per session
VM (yours)
Permission scope
Execution role (IMDSv2)
Execution role, assume a scoped role per task
Instance profile
Persistence
Suspend/resume restores memory + disk, up to 8h
Ephemeral by default; managed session storage keeps a filesystem across stop/resume, up to 1 GB (preview)
Always-on, as long as you keep it
Live session
Interactive shell ( SHELL_INGRESS )
Exec command into live session
Session Manager or browser SSH, plus tmux
Runs containers
Yes, with elevated capabilities enabled
No
Yes, natively
Resource limits
8 GB / 4 vCPU baseline, 32 GB / 16 vCPU peak, 8h
8 GB / 2 vCPU ceiling, 8h
Your instance size
Cost model
Per-second while running, snapshot storage while suspended
Consumption-based, active processing only
Fixed/hourly, pays even when idle
Ops
Serverless, you drive the lifecycle
Serverless, lifecycle managed for you
You run the box
A few scenarios to make it concrete:
  • "I want a 24/7 box I connect to and drive interactively." Lightsail (simple, fixed price) or EC2 (more control).
  • "My CI fires an agent per pull request, running model-generated code I don't trust." Lambda MicroVMs. VM-grade isolation per task, and per-second billing while it runs.
  • "I want a managed home for a coding agent that does long, resumable tasks without owning a server." AgentCore Runtime, as long as the work doesn't need containers.
  • "The agent has to build and run Docker images." A box, or Lambda MicroVMs with elevated capabilities enabled for nested containers. Not AgentCore Runtime.

Pitfalls to watch

  • Isolation invites complacency about permissions. A strong boundary around the environment is not a reason to hand the agent a broad IAM role. Scope the role regardless.
  • Isolation and capability pull against each other. The tighter the sandbox, the more tools break, and you often end up loosening it to get real work done. Loosen deliberately, and know what you gave up.
  • Always-on boxes bill while idle. An EC2 or Lightsail instance you forget about is a standing cost. Stop it when it's not in use, and set a budget alert.
  • Session and resource caps are real. Eight-hour limits on MicroVMs and Runtime, and 2 vCPU / 8 GB on Runtime, will shape what you can run. Design for them rather than discovering them mid-task.
  • Ephemeral means ephemeral. If an environment tears down at session end, anything not committed and pushed, or written to durable storage, is gone. Have the agent push its work.

Where this is going

The trend across all three options is the same: making it normal for an agent to run somewhere other than the machine you're sitting at, inside a boundary you define, and to keep working after you disconnect. Lambda MicroVMs push on isolation and pay-per-use economics, AgentCore Runtime pushes on managed lifecycle and resumable sessions, and a plain VM keeps pushing on control and container support. None of them is the single right answer; the right answer is whichever one matches the six axes for the work in front of you.

Further reading

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article