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.
Investigate market moves and alerts with an agent on your charts
OpenChart lets Claude or Codex annotate chart setups, write indicators, and investigate price alerts, saving research to a local workspace.
Run bulk web-extraction jobs with cheap batch-API agents
A developer uses coding agents for daily work and sets up cheap agents-SDK jobs on batch APIs for large runs like visiting 5000 websites to extract data, plus recurring cloud agent jobs.
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.
Crawl documentation into clean Markdown for AI agents
The author built a documentation crawler for their AI agents that pulled 60 pages of clean Markdown in 49 seconds.
Custom agent
Build a local landmarks map app from one prompt
The author prompted Replit Agent to make a map of local landmarks and got a working Flask web app with an interactive map and Wikipedia integration in about 10 minutes.
Get 5 like this every morning
The best things people got an AI agent to do, each with the prompt to try it.