Run your commands in a private sandbox

Container Basics On Linux (Namespaces/Cgroups)

Run your commands in a private sandbox

🧩 The Challenge

Ever had a script or command act weird, and you suspect it’s seeing some random junk from your current shell environment or network setup? It’s like you need to test it in a completely clean room, but without the overhead of firing up a whole VM or Docker image.

💡 The Fix

There’s a simple command that lets you launch another command into its own set of namespaces – giving it a fresh, isolated view of things like network interfaces, process IDs, or even mount points. It’s awesome for debugging or just ensuring a script runs totally pristine.

unshare --fork --pid --mount-proc --net /bin/bash
# Inside the new shell, you can now check your isolation:
# ip a
# ps aux

⚙️ Why It Works

This command carves out new namespaces for PID, mount, and network, isolating your `bash` session from the host’s view. And because `–mount-proc` is used, processes within this shell see their own PIDs starting from 1, just like a mini-container.

🚀 Pro-Tip: Need to debug a tricky network issue? Pop into an `–net` unshare session and see if the problem persists in isolation.

Linux Tips & Tricks | © ngelinux.com | 10/14/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted