HardwareHardware problems and fixes

Agent container killed: Docker exit code 137 and OOMKilled

An agent container that stops with exit code 137 was killed with SIGKILL. The usual sender on a small host is the kernel's out-of-memory killer, either because the container hit the memory limit you gave it or because the whole machine ran out. Docker records which one it was. This page shows how to confirm it, how to set a limit that fits, and when the answer is a bigger machine.

In short: Check docker inspect: if State.OOMKilled is true, memory killed it. Give the container a limit with headroom over what docker stats shows at its busiest, and keep the sum of all limits below the machine's RAM. If the agent needs more than the host can spare, as NanoClaw (one container per session, about 4 GB recommended) can on a small board, buy memory rather than tuning.

At a glance
Exit code 137128 + 9: the process ended on SIGKILL (Bash convention)
Confirm OOMdocker inspect, State.OOMKilled: true
Live usagedocker stats, MEM USAGE / LIMIT
Hard limit--memory (-m), minimum 6m
Swap--memory-swap is memory plus swap; equal to --memory means no swap
Containersnot given a protected OOM priority, unlike the Docker daemon

Why 137 means killed

Docker's pages do not explain the number 137; it comes from the shell convention for processes ended by a signal. The Bash manual: "When a command terminates on a fatal signal whose number is N, Bash uses the value 128+N as the exit status." SIGKILL is signal 9 on x86 and Arm (signal(7)), and 128 + 9 = 137. SIGKILL "cannot be caught, blocked, or ignored", which is why the agent writes no error of its own: it simply stops.

137 alone does not prove memory. docker stop sends SIGTERM and, if the container "does not exit after the timeout elapses, it's forcibly killed with a SIGKILL signal" (10 seconds by default on Linux): an agent slow to shut down ends with 137 too. The memory case is the one Docker flags.

Confirm it was memory

docker inspect --format '{{.State.OOMKilled}} {{.State.ExitCode}}' <container>

The Docker Engine API defines OOMKilled as "Whether a process within this container has been killed because it ran out of memory since the container was last started", and ExitCode as "The last exit code of this container". true 137 is the answer you are looking for.

To catch the next one as it happens, docker events lists oom among its container events. To see how close a container runs to its limit:

docker stats --no-stream

Its MEM USAGE / LIMIT column is "the total memory the container is using, and the total amount of memory it is allowed to use". On Linux the CLI's figure leaves out the page cache.

Container limit or whole host: two different kills

With --memory set, the cap applies to that container: Docker's docs say that by default, when an out-of-memory error occurs, "the kernel kills processes in a container." Without a limit, a container can use the machine's memory until the kernel runs short. Docker's resource docs describe what happens then: the kernel "starts killing processes to free up memory", and "Any process is subject to killing, including Docker and other important applications." Docker lowers the daemon's OOM priority, but "The OOM priority on containers isn't adjusted", so an agent container is a likely target.

A limit does not make the agent fit. What it changes is where the failure lands: on the container you capped, rather than on whatever process the kernel picks when the whole host runs short, which could be the SSH server or the database.

Set a limit that fits

The flags, as Docker documents them:

FlagWhat it does
-m, --memory"The maximum amount of memory the container can use." Minimum 6m.
--memory-swapmemory plus swap in total; only meaningful with --memory
--memory-swap equal to --memoryno swap for the container
--memory-swap unsetas much swap as the memory setting, if the host has swap (300m becomes 600m in total)
--memory-swap=-1unlimited swap, up to what the host has
--memory-reservationa soft limit below --memory, applied under contention; not a guarantee
--oom-kill-disableonly with --memory set, per Docker's docs

For example, a hard cap of 2 GB with no extra swap:

docker run -m 2g --memory-swap 2g <image>

In Compose, the deploy specification sets the same cap under deploy.resources.limits.memory. Pick the number from docker stats at the agent's busiest moment, plus headroom, and add up every container's cap: the total has to stay below the RAM, with room for the system.

For a Node.js agent in a container, the heap cap is a second limit inside the first. OpenClaw's docs say to pass --max-old-space-size or set NODE_OPTIONS in the container's launch environment, and that its Docker image defaults to MALLOC_ARENA_MAX=2 "to reduce glibc malloc arena fragmentation". A heap cap above the container's limit lets Node grow until the kernel kills it; the heap error itself is covered on JavaScript heap out of memory.

Containers per agent: why NanoClaw needs room

Some agents run one container; NanoClaw runs many. Its README: each agent group gets "its own memory, its own containers (one per session)", and "A single Node host orchestrates per-session agent containers." The agent image is built on node:22.23.4-slim with Chromium for browser automation. NanoClaw asks for "About 4 GB of RAM", and its installer warns below 3,700 MB.

Several sessions at once means several of those containers at once, so the memory a NanoClaw host needs grows with how many conversations run in parallel (our reading of that design, not a figure NanoClaw publishes). 4 GB is the floor it states, not a target for a busy host. The machine we point to for it is on NanoClaw on a Mac mini (Mac mini M4 on Amazon); on a mini PC, a 32 GB SO-DIMM kit (DDR5 SO-DIMM 32 GB on Amazon) adds headroom if the slots take it. Our sizing estimates per agent are on how much RAM an agent needs.

What to buy

Shop links go through /go/ and open Amazon (amazon.fr in the EU and Switzerland, amazon.com elsewhere). As an Amazon Associate we earn from qualifying purchases. Your price does not change and no brand pays for a place on this page (disclosure). We write no price down: it moves, the shop shows today's.

Questions

What does Docker exit code 137 mean?
The process ended on SIGKILL: by the shell convention the exit status is 128 plus the signal number, and SIGKILL is 9. On an agent host the out-of-memory killer is the usual cause; docker inspect tells you if it was.
How do I check if a container was OOM killed?
Run docker inspect --format '{{.State.OOMKilled}}' on the container. The Engine API defines OOMKilled as whether a process in the container was killed because it ran out of memory since the container last started.
Exit code 137 but OOMKilled is false. What else?
Something else sent SIGKILL. The documented case is docker stop: after SIGTERM and a grace period (10 seconds by default on Linux), the container is killed with SIGKILL. Check docker events around that time for a stop or kill.
Should I use --oom-kill-disable?
Docker's docs say to use it only on containers that also have a --memory limit. Without a limit, a container the kernel cannot kill can starve the rest of the host.
Does adding swap stop exit code 137?
It can delay it. With --memory set and --memory-swap unset, a container may use as much swap as its memory limit if the host has swap. It runs slower in swap, and on an SD card swap wears the card.

Sources