---
title: "Set limits on memory and processes · Agent Wranglers"
url: https://agentwranglers.se/playbook/operations/running-the-service/resource-limits
updated: 2026-10-20
licence: "All rights reserved"
---

# Set limits on memory and processes

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Recommended
- Chapter: [Running the service](https://agentwranglers.se/playbook/operations/running-the-service)
- Rule: Give each service a ceiling for memory, processes and open files, so a leak stops that service and not the whole machine.
- How: Set limits in the unit or the container, such as `MemoryMax`, `TasksMax` and `LimitNOFILE` in systemd, or resource limits in Kubernetes. Leave room for the system itself. Restart the service automatically when it dies, for example with `Restart=on-failure`. Caps on what one request may ask for are in [cap the size of every request and answer](https://agentwranglers.se/playbook/adversarial-testing/abuse-and-limits/resource-limits).
- Check: The running unit or pod shows the limits, for example in `systemctl show shop -p MemoryMax`. Kill the process with `kill -9`, and it restarts within seconds.

Example:

```ini
[Service]
MemoryMax=400M
TasksMax=64
LimitNOFILE=4096
Restart=on-failure
RestartSec=2
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers operations playbook: https://agentwranglers.se/playbook/operations/running-the-service/resource-limits`.

- Previous: [Lock the service in a sandbox](https://agentwranglers.se/playbook/operations/running-the-service/service-sandbox)
- Next: [Shut down cleanly](https://agentwranglers.se/playbook/operations/running-the-service/graceful-shutdown)
- [Running the service](https://agentwranglers.se/playbook/operations/running-the-service)
