Run each coding agent session in a cgroup that is killed on completion

I ran into similar issues. Task: I ran into similar issues. Sometimes though there are good language specific solutions. For Rust based worktrees you should definitely check out https://mr-boxington.jdx.dev/ .Regarding swapping, are you sure it's not just from ram backed tmpfs partition? For me that was it and most of the swap was from /tmp. So I created an agressive job that runs frequently to delete all tmp files not used in the last ~2 hours without any command holding handles to it.The other thing I found was that there were a bunch of leftover processes from prior coding agents forking commands and just leaving them. So I had to build a system into my agent spawner to automatically launch each agent session in a cgroup whose processes all get killed on task completion.; tools: Codex. Human role: The original post does not say how a person stayed involved.; limitations: Prerequisites include Linux kernel support for cgroups and administrative privileges to configure process groups. The tmp cleanup job carries a risk of deleting files still needed by active processes if the two-hour window is too short. Source reliability is secondary, as it is a forum comment without detailed technical documentation or benchmark data..

Tools

Codex

Published on Agent Work Atlas:

Overview

I ran into similar issues.

Workflow

I ran into similar issues. Sometimes though there are good language specific solutions. For Rust based worktrees you should definitely check out https://mr-boxington.jdx.dev/ .Regarding swapping, are you sure it's not just from ram backed tmpfs partition? For me that was it and most of the swap was from /tmp. So I created an agressive job that runs frequently to delete all tmp files not used in the last ~2 hours without any command holding handles to it.The other thing I found was that there were a bunch of leftover processes from prior coding agents forking commands and just leaving them. So I had to build a system into my agent spawner to automatically launch each agent session in a cgroup whose processes all get killed on task completion.

Reported result

The source does not report measured outcomes, performance metrics, or confirmation that the issues were fully resolved. It only describes the implementation of the cgroup spawner and tmp cleanup job as responses to observed problems. A measurable acceptance check would be verifying zero orphaned processes remain after agent sessions terminate and monitoring swap usage stability.

Human role

The original post does not say how a person stayed involved.

Limitations

Prerequisites include Linux kernel support for cgroups and administrative privileges to configure process groups. The tmp cleanup job carries a risk of deleting files still needed by active processes if the two-hour window is too short. Source reliability is secondary, as it is a forum comment without detailed technical documentation or benchmark data.

Try it

I need to implement a resource management system for my coding agents to prevent process leaks. First, configure my agent spawner to launch each session in a unique cgroup. Set up a cleanup script that automatically terminates all processes within that cgroup when the agent task completes. Second, create a cron job that runs every hour to delete files in /tmp that have not been accessed in the last two hours, ensuring no active handles exist. Before deploying this to production, run a dry test with a single sample agent session. Verify that the cgroup is created, the agent runs, and the cgroup is fully destroyed upon completion. Check system logs for any errors during the cleanup process. Only proceed with full deployment after confirming the sample test passes and no critical files were accidentally deleted. If you encounter permission errors, ask me for the correct sudo configuration.

Original source

Source reports are not independently verified. Publication date is the catalog publication date, not the original article date.

More cases · Software & development