{"slug": "remote-kirocrew-running-on-a-lambda", "title": "Remote KiroCrew running on a Lambda", "summary": "A developer built KiroCrew-on-Lambda, an open-source CDK setup that runs the OpenCode coding agent as a Lambda Web Function and a Strands harness on a Lambda MicroVM, keeping the KiroCrew release unchanged. The setup connects from a laptop without an open port, keeps conversations in S3, and restricts the Web Function to zero-retention free models; OpenCode was ready 4.3 seconds after a cold start, warm turns took 1–2 seconds, and a 2 GB MicroVM cost $0.126/hour. The developer reports that the free tier's roughly 100-prompt cap caused hung requests until a 40-second wrapper returned HTTP 429, and that the pinned Strands dependency could not install on the Python 3.15 Web Function runtime.", "body_md": "Coding agents burn through a plan quickly. When mine ran out mid-week, I wanted a cheap place to run other agents, away from the laptop. Lambda now has two compute types that fit: Lambda Web Functions, which run an HTTP server behind an endpoint, and MicroVMs, which run a full Linux VM with per-second billing. I used both.\n\nThis post covers what runs where, how the laptop connects without an open port, what the free models do with your data, what it costs, how to tear it down, and what broke.\n\n| Measure | Result | \n|---|---|\n| OpenCode ready after a cold start | 4.3 s | \n| Warm turn on a free model | 1–2 s | \n| Lambda MicroVM cost at 2 GB | $0.126/hour | \n| Model cost on the free tier | $0 | \n\n`opencode serve`, the OpenCode HTTP server, on a free model. It keeps each conversation in S3.\n\nThe setup leaves the KiroCrew release unchanged. The CDK app, adapter, launcher and tests are in the [GitHub repository](https://github.com/awsdataarchitect/kirocrew-on-lambda).\n\n`opencode serve` is a long-lived HTTP server, which is what a Lambda Web Function runs. These limits shaped the design:\n\n| Limit | Value | \n|---|---|\n| Containers | None. The docs and the API show zip packages only | \n| Package size, unzipped | 512 MB | \n| `/tmp` | 512 MB, about 320 MB free once OpenCode has started | \n| CPU and memory | 2 vCPU, 2 GB | \n| Request time | 3 to 900 seconds, default 30 | \n| Time to start listening | 10 seconds | \n| Architecture | arm64 only | \n\nOpenCode is one binary of about 200 MB, so the whole package is 231 MB unzipped and fits. Python runs on the `python3.15` Lambda Web Function runtime, which is in public preview. A thin Python app starts the binary and relays requests to it.\n\n**Strands stays on the MicroVM.** I also installed the Strands harness there and connected it to NVIDIA NIM. That gave me two real harness paths to test: OpenCode through the Lambda Web Function and Strands through the MicroVM. The Lambda Web Function runtime could not install the pinned Strands dependency because its wheel stops at Python 3.14, while Lambda Web Functions offer only Python 3.15.\n\nOpenCode's free models come with different data terms. This is what the [OpenCode docs](https://opencode.ai/docs/console/models/) said on 2026-11-23:\n\n| Model | Retention and use | \n|---|---|\n| deepseek-v4.1-flash-free, hy4-flash-free | Zero retention, no training | \n| big-pickle, tidepool-alpha-free, iceman-free | Used to improve the model | \n| flint-40b-free | Used to improve the model, retained 30 days | \n| beam-free | Not used for training, retained 30 days | \n| nemotron-3.5 free models | NVIDIA trial: logged, don't submit confidential data | \n| mimo-v2.6-flash-free | No terms stated | \n\nI allow only `deepseek-v4.1-flash-free` and `hy4-flash-free` in the Lambda Web Function. Any other model name is rejected.\n\nTwo more things to expect. The catalog changes: the model I started with was gone nine days later, so read it with `opencode models opencode` before you pin one. And the free tier has a cap. After about 100 prompts OpenCode logged \"Free usage limit reached\" and kept retrying, so my requests hung until the 120-second timeout. A newly deployed MicroVM may receive a separate daily quota to keep you going, but I have not verified that. My wrapper gives up after 40 seconds and returns HTTP 429 instead.\n\nClone the [GitHub repository](https://github.com/awsdataarchitect/kirocrew-on-lambda) and install its Node dependencies:\n\n```\ngit clone https://github.com/awsdataarchitect/kirocrew-on-lambda.git\ncd kirocrew-on-lambda\nnpm install\n```\n\nThe deploy script builds the Lambda Web Function package, bootstraps CDK if needed and deploys both stacks. From the repository root:\n\n```\n./deploy.sh          # both stacks, about 8 minutes\n./deploy.sh check    # live Lambda Web Function check\n```\n\nPrerequisites: AWS CLI v2 with credentials, Node 22 or newer, [uv](https://docs.astral.sh/uv/), and the Session Manager plugin on the laptop. The Strands harness reads a free NVIDIA NIM key from an SSM Standard String parameter. Create it before deployment, without committing the value or using `SecureString`:\n\n```\nread -rsp \"NVIDIA NIM API key: \" NVIDIA_NIM_API_KEY; printf '\\n'\naws ssm put-parameter \\\n  --name /nim-free/api-key \\\n  --type String \\\n  --value \"$NVIDIA_NIM_API_KEY\" \\\n  --overwrite \\\n  --region us-east-1\nunset NVIDIA_NIM_API_KEY\n```\n\nThe deploy role needs permission to read that parameter. The CDK stack passes the parameter reference to the MicroVM; the key is not written into the image, repository or logs.\n\n```\ncrew/scripts/crew.sh up          # launch one crew, about a minute to ready\ncrew/scripts/crew.sh status      # phase and installed KiroCrew version\ncrew/scripts/crew.sh down        # stop billing, save state\n```\n\nThe image build runs the official KiroCrew installer (`--channel stable`), so each rebuild picks up the latest stable release. The installer checks a signed release feed and the wheel's SHA-256 before it installs anything, and it needs `openssl` for that. Read the pinned Strands versions from the installed release instead of copying them, so a newer KiroCrew brings its own.\n\nThe gateway's home folder is copied to S3 every minute and on shutdown, so a new VM continues your sessions. The VM lives at most one hour by default (the platform maximum is 8), and it bills only while it runs.\n\nThe familiar Remote Crew choices are a cloud crew, which runs on an EC2 instance in your AWS account, and a local crew, which runs on a machine you already have. This blog adds the Lambda MicroVM option. Fargate provides another remote path when a chat API is enough:\n\n| Option | What it is | \n|---|---|\n| Cloud crew | A managed install on an EC2 instance in your AWS account, billed per second while it runs | \n| Local crew | You set up a crew on a machine you already have | \n| Fargate task | A chat API on an ECS Fargate task. KiroCrew tunnels to it with `aws ssm start-session` ; the card shows a URL to call, with no dashboard and no token. It needs the AWS CLI, Session Manager plugin and permission for SSM Session Manager. | \n| **Lambda MicroVM (this blog)** | A crew on a Lambda MicroVM, billed per second while it runs and wired up with SSM | \n\nThe three Remote Crew connection methods are SSH, AWS SSM Session Manager and the Fargate task chat API. This post uses AWS SSM Session Manager for the MicroVM.\n\nSSH needs an open port and a key. A MicroVM has neither. SSM works the other way round: the MicroVM calls out to AWS, so nothing listens. The MicroVM registers itself as a managed node, and your laptop asks SSM to run a command on it and to forward a port. Who may do that is an IAM decision.\n\n`mi-` and shows Online.`crew`, the gateway's port, and the `kirocrew` path on the MicroVM. `crew.sh remote-config` prints these values.`kirocrew token` on the MicroVM to mint a login token. Session Manager forwards the gateway's port to your laptop.`ssm:SendCommand`, `ssm:GetCommandInvocation` and `ssm:StartSession` on that node. There is no key to lose and no inbound rule.\nThe role the MicroVM assumes only needs the `AmazonSSMManagedInstanceCore` managed policy. I did not need Secrets Manager or KMS for any of this. See [hybrid activations](https://docs.aws.amazon.com/systems-manager/latest/userguide/activations.html).\n\nI verified this path with the final image: the Remote Crew pane connected over SSM, minted a token, opened the gateway and completed a chat turn through the OpenCode Lambda Web Function.\n\nKiroCrew's dashboard can be published on a tailnet, and it has a Connect your phone control in the side rail. On the laptop, enable the dashboard's Tailscale access and use the displayed tailnet address. On the iPhone, install and sign in to Tailscale, turn on **Use Tailscale DNS settings** in the app, then open that address. The phone can reach the same remote crew without exposing the gateway to the public internet.\n\nThe final setup was checked from an iPhone. The screenshot below shows the phone connected to the remote KiroCrew dashboard.\n\n**The SSM agent needs root, and the VM forbids it.** The VM runs with the no-new-privileges flag, so `sudo` refuses to start: \"The 'no new privileges' flag is set, which prevents sudo from running as root.\" The agent runs as root and keeps its credentials under `/root` ([docs](https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent-technical-details.html)), so running it as your app user does not work. I start the container as root and run one small helper. It accepts a single request on a unix socket, checks the region, activation id and code against strict patterns, registers once, and starts the agent. Everything else drops to a normal user.\n\n**Run Command's PATH is short.** KiroCrew wraps remote commands in `sudo -u crew -i bash`. With a stand-in `sudo` in `/usr/local/bin`, Run Command answered \"sudo: command not found\", because its PATH has `/usr/bin` but not `/usr/local/bin`. Install the stand-in in `/usr/bin`.\n\n**A suspended VM drops your session.** I had set the idle policy to suspend the VM after 5 minutes, and by the time I pressed Connect it was suspended. A suspended VM freezes the SSM agent, and Session Manager does not wake it, so the port forward timed out after 25 seconds. Set the maximum idle time to the VM's lifetime and let the lifetime cap bound the cost.\n\n**Connect failed with \"No such file or directory\" for the kirocrew path.** The Remote Crew entry stores the path to `kirocrew` on the remote. An entry left over from an earlier attempt pointed at a path that did not exist on this VM. Set it to the installer's path, `/usr/local/bin/kirocrew` here.\n\n**The Lambda Web Function answered 403 to signed requests.** The endpoint wants a signed `x-amz-content-sha256` header. The JavaScript signer adds it by default and botocore does not. Add the header before you sign.\n\n**The prompt is longer than you think.** KiroCrew sends its whole agent prompt before your message. My first wrapper cut prompts at 2,000 characters, so the model never saw the question and replied to the preamble. Cap at 200,000.\n\n**HTTP 429 from the endpoint.** Read the `lambda-web-error-type` header. `Platform.EndpointMaxEnvThrottle` means the endpoint hit its `maxEnvironments` limit. I had it at 2, the lowest allowed. Raise it. See [scaling behaviour](https://docs.aws.amazon.com/lambda/latest/dg/web-functions-scaling.html).\n\n**The server may start your app in more than one process.** Two `opencode serve` processes on one home folder gave \"database is locked\", and requests failed after waiting 60 seconds. A file lock lets one process start it and the others reuse it.\n\n**Keep the conversation outside the environment.** Environments scale in and out, and `/tmp` is lost with them. I store each conversation as a transcript in S3. A new environment creates a fresh OpenCode session and posts the earlier turns with `noReply`, which makes no model call. I tried `opencode export` and `import` first. Thirty concurrent calls timed out at 30 seconds on 2 vCPU, because each call starts a process. In a test with 36 sessions across two environments, turns that moved between environments came back restored and still knew the code word.\n\n**S3 Files did not fit.** A Lambda Web Function has no file system setting in its service model. A MicroVM accepts one default-route network connector, and a VPC connector without a NAT gateway could not reach SSM or the model API, so the SSM read timed out. I copy state with the S3 API instead.\n\n**The image build failed.** The installer needs `openssl` to verify its feed, a root-owned uv cache blocked it when it ran as a normal user, and a Strands package spec had its extra in the wrong place (`pkg==1.0[extra]` instead of `pkg[extra]==1.0`). A failed image build rolls the stack back and deletes its log group, so copy the build log while it runs.\n\nPrices are for us-east-1 on Arm, from the [Lambda pricing page](https://aws.amazon.com/lambda/pricing/) and the Price List API.\n\n| Item | Rate | \n|---|---|\n| MicroVM, 2 GB and 1 vCPU | $0.0000276944 per vCPU-second plus $0.0000036667 per GB-second, so about $0.126 per hour | \n| Lambda Web Function | $0.30 per million requests, the same vCPU and memory rates, billed on active CPU, not on waiting | \n| MicroVM snapshots | $0.00155 per GB read at launch, $0.0038 per GB written at suspend, image storage $0.08 per GB-month with a one-week minimum | \n| Amazon ECR | No private ECR application image is stored in this design. Lambda builds the MicroVM image from the S3 code artifact; the Dockerfile uses public ECR base images. If you switch to a private ECR base image, standard [Amazon ECR storage and applicable data-transfer charges apply](https://aws.amazon.com/ecr/pricing/) | \n| Session Manager, Run Command | $0.05 per connection, $0.002 per command [AWS blog](https://aws.amazon.com/blogs/multicloud/centralize-your-multicloud-management-in-aws-systems-manager-with-automated-onboarding-and-simplified-pricing/) | \n| Free models, SSM Standard parameter, hybrid activation | $0 | \n\nAn example month: a crew for 2 hours a day over 20 days, one Connect per day, 100 turns a day.\n\n| Part | Calculation | Cost | \n|---|---|---|\n| MicroVM | 40 hours at $0.126 | $5.04 | \n| SSM | 20 connections at $0.05 and 20 commands at $0.002 | $1.04 | \n| Lambda Web Function | 2,000 requests at about $0.0000192 | $0.04 | \n| **Total** |  | **about $6.12** | \n\nThe total includes the MicroVM, Lambda Web Function, SSM connection and command charges in this example. S3 storage, S3 requests and CloudWatch Logs add usage-based charges that depend on retention and traffic, so check those separately in Cost Explorer. The Lambda Web Function figure comes from 648 requests in my logs, which used 442 vCPU-seconds, including cold starts. It leaves out memory, which I did not measure. The MicroVM bills while it runs, so stop it with `crew.sh down` when you are done.\n\n```\ncrew/scripts/crew.sh down        # terminates the VM and deregisters its SSM node\n(cd crew && ../node_modules/.bin/cdk destroy) && (cd webfn && ../node_modules/.bin/cdk destroy)\n```\n\nThe crew's state bucket is retained on purpose; empty and delete it by hand. Image storage has a one-week minimum. Remove the Remote Crew entry in Settings, since its `mi-` id is gone with the VM.\n\n`python3.15`, which can change.\nWhat started as a weekend project to test Lambda Web Functions on the new Python 3.15 runtime grew into an experiment in launching KiroCrew from an iPhone while its gateway ran inside Lambda: OpenCode on a Lambda Web Function, Strands with NVIDIA NIM in a MicroVM, SSM access from a laptop, and the same crew reachable from an iPhone over Tailscale.\n\nThe [GitHub repository](https://github.com/awsdataarchitect/kirocrew-on-lambda) contains the complete CDK project, launcher and setup instructions.\n\nNow, go build!", "url": "https://wpnews.pro/news/remote-kirocrew-running-on-a-lambda", "canonical_source": "https://dev.to/aws-heroes/remote-kirocrew-running-on-a-lambda-3jbn", "published_at": "2026-11-25 23:39:26+00:00", "updated_at": "2026-11-25 23:43:07.783566+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "ai-infrastructure", "developer-tools", "mlops"], "entities": ["OpenCode", "AWS Lambda", "KiroCrew", "Strands", "NVIDIA NIM", "AWS CDK", "GitHub"], "also_reported_by": [], "takeaway": "Running OpenCode as a Lambda Web Function on zero-retention free models gave 4.3-second cold starts and 1–2-second warm turns at $0.126/hour for a 2 GB MicroVM, but the free tier's ~100-prompt cap hung requests until a 40-second wrapper returned HTTP 429.", "recommendation": {"advice": "Pin only zero-retention free models, re-check the catalog before pinning since models disappear, and wrap agent calls with a 40-second timeout that returns HTTP 429 when the free-tier cap is hit.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/remote-kirocrew-running-on-a-lambda", "markdown": "https://wpnews.pro/news/remote-kirocrew-running-on-a-lambda.md", "text": "https://wpnews.pro/news/remote-kirocrew-running-on-a-lambda.txt", "jsonld": "https://wpnews.pro/news/remote-kirocrew-running-on-a-lambda.jsonld"}}