---
title: "Run containers as a user without root · Agent Wranglers"
url: https://agentwranglers.se/playbook/infrastructure/containers-and-orchestration/non-root-containers
id: INF-73
level: Required
applies: servers
risk: takeover
updated: 2026-10-27
build: a2a6bdfed830
tokens: 717
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Run containers as a user without root

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Containers and orchestration](https://agentwranglers.se/playbook/infrastructure/containers-and-orchestration.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: INF-73
- Level: Required
- Chapter: [Containers and orchestration](https://agentwranglers.se/playbook/infrastructure/containers-and-orchestration.md)
- Rule: Switch to a user without root with `USER` before the app starts. Give that user write access only to the folders the app writes.
- Check: `docker run --rm shop id -u` prints a number other than 0.
- Risk: An account or system taken over
- Applies when: The project runs its own servers, virtual machines or containers.
- How: Many base images ship such a user, for example `node` in the Node images. Create the data folder and change its owner before the `USER` line. Drop extra capabilities at run time, for example with `cap_drop: [ALL]` in Compose. The [service sandbox](https://agentwranglers.se/playbook/operations/running-the-service/service-sandbox.md) gives the same idea for services without containers.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Dockerfile example

```dockerfile
RUN mkdir -p /data && chown node:node /data
USER node
```

## Sources

- [NIST SP 800-190 Application Container Security Guide](https://csrc.nist.gov/pubs/sp/800/190/final)
- [OWASP Docker Security Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html)

## Related rules

- OPS-33 [Lock the service in a sandbox](https://agentwranglers.se/playbook/operations/running-the-service/service-sandbox.md) in Operations and observability
- INF-74 [Never give a container control of the host](https://agentwranglers.se/playbook/infrastructure/containers-and-orchestration/no-privileged-containers.md) in Infrastructure and environments

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/infrastructure/containers-and-orchestration/non-root-containers">Agent Wranglers infrastructure and environments playbook</a>`. In code you write, add a comment next to it with the same link.

- Next: [Never give a container control of the host](https://agentwranglers.se/playbook/infrastructure/containers-and-orchestration/no-privileged-containers.md)
- [Containers and orchestration](https://agentwranglers.se/playbook/infrastructure/containers-and-orchestration.md)
