encapsule
Run isolated toolbox containers with podman
https://github.com/juhp/encapsule
| Stackage Nightly 2026-10-11: | 0.6 |
| Latest on Hackage: | 0.6 |
encapsule-0.6@sha256:594c929c09c4422bb1043746e316d63a73ec03e2d401502f2639da2fd894dbe9,4243Module documentation for 0.6
There are no documented modules for this package.
encapsule
CLI tool to run developer containers, isolating your home directory and host from general effects inside the containers: “encapsules” a project and/or temp home dir together with select “capabilities”.
Originally derived from toolbox-constrained.
Run a (toolbox) container or image as
an isolated podman container. Unlike with toolbox create, this does not
bind-mount your home directory or integrate with the host by default.
You can explicitly choose what dir(s) or file(s) to mount or features to enable,
selecting user-configured “capabilities” that the encapsule container can access.
Most encapsule subcommands act on an image.
- If you wish to use an existing toolbox container as a starting point you can
commitit to an “encapsule” container image.- Note your original toolbox container is left untouched: its system configuration and fs are just used as the base fs for the encapsule image (though its original bind mounts including $HOME will be not be included by default).
- Alternatively you can roll your own image or run a vanilla image like
fedora(fedora:latest),fedora-toolbox:45,ubuntu:latest, etc.- Toolbox images or containers are generally recommended for development, but it doesn’t have to be a toolbox container as such.
A typical invocation might look like:
$ encapsule someimage:tag --cap my-config --home ~/isolated --project projects/abc
(directories can be relative).
Encapsule images and containers are prefixed by encapsule-,
but there is no need to use this prefix normally - it is implicit.
Usage
$ encapsule --version
0.6
$ encapsule --help
encapsule
Usage: encapsule [--version] COMMAND
Run a toolbox image in an isolated podman container
https://github.com/juhp/encapsule#readme
Available options:
-h,--help Show this help text
--version Show version
Available commands:
list List encapsule images and containers
list-caps List available capabilities
pull Pull a container image with podman
rm Remove an encapsule container
rmi Remove an encapsule image
stop Stop an encapsule container
backup Create a tarball backup of a directory
commit Commit an encapsule image from a container
create Create an encapsule container
enter Connect to an encapsule container
run Run a temporary encapsule container
There are 3 main commands: run, create, and enter.
run and create share many options.
run command
run starts a temporary encapsule container (removed on exit) from an image.
$ encapsule run --help
Usage: encapsule run IMAGE [-v|--volume HOST:CONTAINER[:opts]]
[-e|--env KEY[=VALUE]] [--path DIR] [-i|--init CMD]
[--cap NAME] [--pull] [--root | --user USER]
[(-H|--home DIR[:opts]) [--backup-home]]
[(-p|--project DIR[:opts]) [--backup-project]]
[-n|--name NAME] [--readonly]
[--no-network | --network-host] [--sudo] [--no-skel]
[--podman-opt OPTION] [--debug] [--dryrun] [[--] CMD]
Run a temporary encapsule container
Available options:
-v,--volume HOST:CONTAINER[:opts]
Bind mount (user's files default to selinux :z)
-e,--env KEY[=VALUE] Set or pass through an environment variable
--path DIR Prepend a directory to PATH inside the container
-i,--init CMD A bash snippet run when creating the encapsule
container
--cap NAME Enable a capability from the config file
--pull Pull newer container image
--root Run as root (shorthand for --user root)
--user USER Override container user [default: host/image user
with host UID]
-H,--home DIR[:opts] Mount a directory as a writable home (created if
missing; use DIR:O to overlay)
--backup-home Tarball home directory before starting
-p,--project DIR[:opts] Mount a (project) directory as workdir (use DIR:O to
overlay)
--backup-project Tarball project directory before starting
-n,--name NAME Optional container name (prefix with '^' prefix to
skip 'encapsule-' prefix)
--readonly Make the encapsule container filesystem read-only
--no-network Disable network access
--network-host Share the host network (including localhost ports)
--sudo Set up passwordless sudo for the container user
--no-skel Don't copy /etc/skel into an empty home
--podman-opt OPTION Pass an option directly to podman
--debug Show debug output
--dryrun Print the podman command instead of running it
-h,--help Show this help text
Use --network-host with run (or create) to make servers on arbitrary
container localhost ports reachable on the same host localhost ports.
This also allows access to host-local services and shares the host’s port
space. It cannot be combined with --no-network. Without either option,
Podman’s default isolated container networking applies.
create command
create is similar but creates a reusable container for a project and/or temp home.
enter command
enter is used to join an existing (typically running) encapsule container.
An optional command can be given, as with run:
$ encapsule enter my-toolbox -- tmux
By default enter uses the user matching the host UID. Use --root (or
--user root) when administrative access is needed:
$ encapsule enter --root my-toolbox
commit command
commit saves a container as an encapsule image (encapsule-CONTAINER by default).
Use -n/--name NAME for a custom image name (becomes encapsule-NAME, or ^NAME to skip the prefix).
list command
Lists the encapsule images and containers:
$ ncpsl list
localhost/encapsule-harness:latest 6.15 GB 12 days ago
encapsule-harness-encapsule Up 31 hours
encapsule-fedora Up 29 minutes
encapsule-fedora-toolbox-45 Up 5 seconds
backup command
This is really independent of encapsule.
It provides a simple way to create a backup tarball of a (git) project or dir.
There are also runtime --backup-project and --backup-home options.
Examples
# Temporary isolated shell without host fs access
~$ encapsule run fedora-toolbox:44
# Mount current (project) directory path and set it as the working directory
# (also names the container after the project, e.g. encapsule-ubuntu-myproj)
~/myproj$ encapsule create ubuntu -p .
# Bind mount a volume
$ encapsule run fedora -v ~/data:/data
# create a custom "encapsule-fedora-toolbox-45" image from a toolbox container
$ encapsule commit fedora-toolbox-45
# Mount a temp "home" directory in the committed encapsule image
$ encapsule run fedora-toolbox-45 --home ~/tmp/home
# Save another encapsule image named "encapsule-dev"
$ encapsule commit --name dev fedora-toolbox-45
# Use capabilities from one's config
$ encapsule create dev --cap ssh --cap git
# Remove encapsule container
$ encapsule rm dev
# create "encapsule-my-toolbox" image
$ encapsule commit fedora-toolbox-45 --name my-toolbox
# Read-only container filesystem
$ encapsule run my-toolbox --readonly
# Set environment variables and prepend to PATH
$ encapsule run my-toolbox -e MY_VAR=hello -e LANG --path ~/.local/bin
# Run a specific command
$ encapsule run my-toolbox -- ls /
# Run a setup init scriptlet
$ encapsule run fedora-toolbox:45 -p proj --init "dnf install -y gcc make"
# Dry run: print the full podman command without running it
$ encapsule run --dryrun my-toolbox
There is a rmi command to remove an encapsule image no longer needed.
Capabilities
Capabilities define reusable groups of volumes, environment variables,
PATH entries, and init commands in /usr/share/encapsule/config.toml
and ~/.config/encapsule/config.toml:
[capabilities.ssh]
volumes = ["~/.ssh:~/.ssh:ro"]
[capabilities.git]
volumes = ["~/.gitconfig:ro"]
[capabilities.wayland]
env = ["WAYLAND_DISPLAY", "XDG_RUNTIME_DIR"]
volumes = ["$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"]
security_opts = ["label=disable"]
[capabilities.rust]
path = ["~/.cargo/bin"]
There is an example user config file: example/config.toml.
Use encapsule list-caps to list all the available defined capabilities.
Each capability can define:
volumes: list of bind mount specsenv: list of environment variables to set or pass throughpath: list of directories to prepend to$PATHinit: a bash snippet to run on encapsule container creationsecurity_opts: list of--security-optvalues passed to podman
~ and envvars are expanded in volume and path specs.
If the host and container paths are the same, you can use the shorthand
PATH[:opts] instead of PATH:PATH[:opts].
The default defined capabilities live in the bundled data/config.toml file.
These capabilities can be overridden by XDG system config files
(under XDG_CONFIG_DIRS): by default /etc/xdg/encapsule/config.toml.
User settings (under XDG_CONFIG_HOME) take precedence over these settings;
earlier directories in XDG_CONFIG_DIRS take precedence over later ones.
Nested tables are merged, so overriding one field of a capability preserves
its other system defaults. Arrays are replaced rather than appended;
use an empty array to clear a default.
Note that an existing XDG system config, even an empty file, replaces the bundled default definitions entirely, whereas the user config will augment or modify them.
To be quite clear, no capabilities are used by default: they need to be explicitly enabled on the commandline. The definitions just make them available to use.
How it works
- Optionally commits the named toolbox container to an encapsule image (using
podman commit). - Runs
podman runwith--userns=keep-idso you are your own user, not root - Drops from root with
runuserif present, otherwisesudo -u. Explicit--user root/--rootruns directly as root (enterusespodman exec --user) - Does not grant privilege escalation by default.
--sudoopts into a passwordless sudoers entry when the image containssudo - Bind mounts get SELinux
:z(shared) labels automatically, so multiple containers can safely access the same directories - When
-p/--project DIRis used (and--nameisn’t), the container name includes the project directory’s name (e.g.encapsule-mytoolbox-myproject), so you can run the same toolbox against different projects at the same time in separate encapsule containers. For invocations with the same name, the container name gets differentiated by pid.
Installation
Encapsule is packaged in Fedora: https://src.fedoraproject.org/rpms/encapsule
Building from source
Install cabal-install and ghc.
cabal install
Build with stack
Alternatively you can build with:
stack install
Build release
To build the latest release: cabal install encapsule
or stack install encapsule.
Tests
cabal test runs an hspec suite that drives the encapsule CLI
(--dryrun against local images, plus an optional live run).
It needs podman and skips missing images.
Default images are fedora:latest and ubuntu:latest.
Override with ENCAPSULE_TEST_FEDORA and ENCAPSULE_TEST_UBUNTU.
Live tests need a TTY, or set ENCAPSULE_LIVE=1 to try without one.
ENCAPSULE selects a different encapsule binary.
cabal test
cabal bench times encapsule run --dryrun and a short run -- true
against a local image (same env vars as tests). It requires podman and an
image. It measures wall-clock time. To log timings:
cabal bench --benchmark-options '--csv /tmp/encapsule-bench.csv --time-limit 3'
# later: --baseline /tmp/encapsule-bench.csv
Runtime Requirements
- podman
- An existing (toolbox) image (optionally created from a container with
toolbox create).- Use
encapsule pull(orpodman pull) to get an image first.
- Use
- Encapsule has only been tested on Linux.
Related projects
I already mentioned toolbox-constrained from which the initial code was derived.
There is also similarly schupfn which uses QEMU to run a toolbox container image in a VM with a direct private ssh connection.
Another somewhat related project is podenv, which “provides a declarative interface to manage containerized applications.”
For stronger sandboxing and isolation, specially network, consider using OpenShell. At some point this project might support openshell perhaps.
There is also litterbox which has quite a lot of features and though somewhat opinionated, for example like openshell also supports landlock confinement.
Disclaimer
The simple isolation provided is limited best effort and comes with no (security) warranty. Please use this tool at your own risk.
Reports, suggests, and contributions to improve the tool are very welcome.
Contribute
encapsule is at https://github.com/juhp/encapsule and distributed
under the Apache-2.0 license.
Changes
encapsule releases
0.6 (2026-10-10)
- make passwordless sudo setup opt-in with
--sudo(replaces--no-sudo) - add
--rootas shorthand for--user root enter: add--root/--usercommit: use podman instead of buildah- install default capabilities in datadir/config.toml
(can be overriden by
XDG_CONFIG_DIRSfiles and augmented by user config) - add
--network-hostto share host networking for local servers - add
pullcommand (currently just a wrapper forpodman pull)
0.5.1 (2026-09-15)
enterbugfix: -e=LANG must precede containerenter: allow an optional command likerun(enter TOOLBOX -- tmux)
0.5 (2026-09-14)
run,create: now always act on a container imagerun,create: set--workdironly when the path exists at startrun,create:--passwd-entryso keep-id does not set home to/run,create: fall back tosudo -uwhenrunuseris missingrun --debugnow also outputs podman command like--dryrunenter: use$HOMEas workdir when the container workdir is/enter: usepodman exec --userinstead ofrunusercommit: add--nameto set the encapsule image namecommit: replacesrefreshwith simpler logicrmi: fix –dryrun (0.4.1 logic regression)backupnow excludes local git ignored files- bind-mount
/etc/localtime - export
LANG=C.UTF-8(override with-e LANG=Cor another locale) - check first if runuser and sudo are in the container image
- use image passwd user with the same UID as the host (e.g. support ubuntu)
- container
$HOMEfollows the image passwd home when it is a real directory;--homemounts there - simplify setup script: no longer installs sudo and util-linux
- now also setup home if no runuser
--no-sudono longer attempts to remove sudo- add
--useroption to override the container user - dryrun/debug colors podman flag names in cyan (honors
NO_COLOR) - add hspec tests (
cabal test; needs podman and local images) - add tasty-bench suite (
cabal bench; needs podman and a local image)
0.4.1 (2026-08-07)
- require volume host paths to exist
- drop
-Pfor--pathand add-Hfor--home - copy
/etc/skelinto home if~/.bashrcis missing (--no-skelto skip) - config.toml: add dbus, dconf, machine-id capabilities
- support mount options for
--homeand--project(like:Ofor overlay) - only auto SELinux
:zfor user-owned paths and not overlay:O - create
--project/--volumemount points in –home for $HOME targets - add
backupcommand to tarball a directory (prompts if >100MB) run,create:--backup-home/--backup-projectto tarball those dirsrefresh: always update image (drop freshness checks and--force)- sanitize
.to-in container hostname
0.4 (2026-08-04)
- convert to using subcommands
list: separate images and containers and include image tags- introduce
createto make a permanent container - add
entercommand (formerly –join) run: automate unique container name (drop –unique)- new
refreshcommand to update an existing encapsule toolbox image if container has layered changes - correct some container name sanitizations
- check that the host project dir actually exists
- improve HOME handling and mount project to its own path for clarity
- also default workdir to home for image
- add
--pullforrunandcreateto pull a newer image - Allow mounting $HOME (without SELinux :z relabeling)
0.3 (2026-07-20)
- project renamed from constrained-toolbox
- rename
--persistentto--keep - add
--listcommand to show encapsule containers and images - add
--no-sudoto remove sudo from the container - check toolbox container exists before buildah commit
- support running container images directly (name:tag)
- add
--nameoption - add
--debugflag for verbose startup output - use
--name ^...to reference a full container name explicitly - export TERM and COLORTERM
--deleteand commit image now respect –dryrun- use shell-monad for installSetup Script
- installScript now respects
--no-sudoand outputs “installing” - use xdg-basedir for config file
- error for
--project/--homeon HOME --projectnow names the container after the project directory too, so different projects can run concurrently in separate containers- add
--podman-optto pass options directly to podman
0.2.1 (2026-07-17)
- add –delete container command
- handle missing container gracefully in –stop and –remove
- default to ephemeral containers again, use –persistent to keep
0.2 (2026-07-16)
- add
--homeoption to mount a directory as a writable home - name the container and exec into it if already running
- add
--uniqueoption to run a separate container instance - make home directory writable and workdir by default
- change
--deleteto--delete-imagestandalone command - add
--ephemeral, restart stopped containers - error for unused options when joining running container
- add –stop command
0.1 (2026-07-03)
- initial release with
--deleteand--projectoptions - defaults to :z shared bind mounts
--capsto list user’s defined capabilities- wayland: fix socket handling in SELinux labeling
- add
security_optscapability field - support PATH[:opts] shorthand for same host/container mount path (makes config incompatible with toolbox-constrained)
- add
--no-networkoption to disable network access - exit cleanly on shell error instead of throwing an exception