Contain agent runs and clear old temp files

A developer limited each coding run to a separate cgroup and added a recurring cleanup for forgotten temp files.

Done with Codex· Advanced· Oct 2026

What they did
They noticed swap pressure coming from a tmpfs-based /tmp and from processes left behind by earlier agent runs. In response, they set up a frequent housekeeping job that removes temporary files older than about two hours, but only if nothing still has them open. They also wrote an agent launcher that places every coding session in its own cgroup and ends all processes in that group once the work is done.
How it went
The write-up says these changes reduced the swap problem and the lingering processes. It does not provide any benchmark numbers or a before-and-after comparison.
Tips
Check the real source of swap use before assuming the agents are to blame. The temp-file cleaner is intentionally conservative, so it skips files that are still open.

Try it yourself with Codex

In [repo or project], create a small launcher for [Linux distro or init system] that starts each coding-agent run inside a dedicated cgroup. When the run ends or fails, stop every process still attached to that cgroup. Add a scheduled task that removes stale files from [tmp path] once they have been idle for about [number] hours, but only if no process currently has them open. Before any deletion or process termination outside the test case, list exactly what would be affected and wait for my approval.

Fill in the [brackets]. Agents can make mistakes, so review anything before it is sent, paid or deleted.

Get 3 agent uses like this every morning

With the day's top AI news. Free, and one click to unsubscribe.