unshare

Run a program with some namespaces unshared from the parent.

medium risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
What it does

unshare creates new namespaces (network, PID, mount, user, UTS) and runs a command in them, isolated from the parent. Used to understand container internals, test namespace isolation, and create lightweight sandboxes without full container runtime.

Common flags
FlagMeaning
--netCreate new network namespace
--pidCreate new PID namespace
--mountCreate new mount namespace
--userCreate new user namespace (unprivileged)
--forkFork before executing command
Examples
unshare --net bashShell with its own isolated network namespace (no interfaces) · explain & risk-check →
unshare --user --map-root-user bashShell with root privileges in user namespace · explain & risk-check →
unshare --pid --fork --mount-proc bashIsolated PID namespace (only sees own processes) · explain & risk-check →
Pro tip

Use `unshare --net bash` to test how your app behaves with no network — quickly reveals hardcoded DNS lookups or network dependencies you didn't know existed.

Related
nsenter docker exec systemctl
Open the full explainer →More in System & Processes

Reference text is hand-written and may be incomplete — check man unshare for your version. Test destructive commands on a non-production system first.