Run each coding agent session in a cgroup that is killed on completion
A developer built an agent spawner that launches each coding agent session in its own cgroup and kills leftover processes when the task completes, plus a job that clears stale tmp files.
Done withCodex
- What they did
- The developer traced heavy swapping to a RAM-backed tmpfs /tmp and to processes that earlier coding agents had forked and abandoned. They added a frequently run job that deletes tmp files unused for about two hours and not held open by any command. They also built their agent spawner to launch each session in its own cgroup, killing every process in it when the task finishes.
- How it went
- The source gives no measurements. It says the cleanup job and per-session cgroups addressed the swap usage and the leftover processes, but it is a brief forum comment with no before-and-after figures.
- Worth knowing
- Check whether swap is really coming from a RAM-backed tmpfs /tmp before blaming the agents; the cleanup job only removes files with no open handles.
Try it yourself with Codex
In my repo at [path], write a small agent spawner script for [Linux distro or systemd setup] that launches each coding agent session in its own cgroup and kills every leftover process in that cgroup when the task finishes or fails. Also add a scheduled job that deletes stale files older than [number] hours in [tmp directory]. Finish by running a test session that leaves a background process behind and showing me that it gets cleaned up. Before deleting any files or killing processes outside the test, show me what would be removed and wait for my approval.
Want help getting this working? Join the Vibe Coding Academy ↗ Run by Alex Finn, who also runs this site.
Source: HN · Oct 17, 2026
Related use cases
Turn tickets into merged pull requests
Pulls tasks from GitHub Issues or Linear, then runs Claude Code or Codex in isolated Kubernetes pods to carry each one through to a PR.
Handle family errands and recipe sorting with Codex
A communications professional had Codex email her son's doctor for a refill and sort 240 recipes down to 62 family-fit ones into an index, spreadsheet and Drive folder.
Build and publish a BaZi chart reading agent
Built solo with coding agents, an agent computes BaZi charts, interprets them, detects language and takes on-chain payments for readings.
Build a C compiler with a team of parallel agents
Anthropic's engineering write-up on tasking Opus 4.6 agent teams with building a C compiler.
Debug frontend UI bugs with a browser agent
A frontend developer pairs Claude in Chrome with Claude Code to open the app, click through it, read the DOM, check console errors and network requests, and fix UI bugs.
Run sandboxed Claude Code fleet sharing files via MCP
A developer runs a fleet of sandboxed Claude Code instances that share files through MCP tools on a virtual filesystem, with an orchestrator handling AWS storage and audit logs.
Get 5 like this every morning
The best things people got an AI agent to do, each with the prompt to try it.