packages feed

workcell-0.1.2: README.md

# Workcell

Workcell is a Linux CLI tool using Bubblewrap to setup Linux namespaces
to run programs with a read-only sysroot, an isolated homedir and restricted
to a writable project/work dir (and runtime). By default it attempts private
networking using pasta, falling back to host networking if it fails.

## Usage

`$ workcell --version`

```
0.1.2
```

`$ workcell --help`

```
workcell

Usage: workcell [--version]
                [COMMAND | [--dryrun] [-p|--project DIR[:(ro|rw|O)]]
                  [-H|--home DIR] [-v|--volume SOURCE[:DEST][:(ro|rw|O)]]
                  [-e|--env KEY[=VALUE]] [--wayland] [--x11] [--dbus]
                  [--share-processes] [--share-filesystem]
                  [--network-host | --network-none | --network-private]
                  [[--] CMD ARG...]]

  Run inside bwrap with an isolated home and writable project

Available options:
  -h,--help                Show this help text
  --version                Show version
  --dryrun                 Print the bubblewrap command without changing files
  -p,--project DIR[:(ro|rw|O)]
                           Project access (default: rw; :O for temporary
                           overlay; directory defaults to cwd, excluding HOME
                           and ancestors)
  -H,--home DIR            Persistent writable home (created if missing)
  -v,--volume SOURCE[:DEST][:(ro|rw|O)]
                           Extra mount (:O for temporary directory overlay;
                           default: same path, read-only)
  -e,--env KEY[=VALUE]     Set or pass through an environment variable
  --wayland                Expose the Wayland display socket for graphical
                           applications
  --x11                    Expose the local X11 display socket and
                           authentication file
  --dbus                   Expose the desktop D-Bus session socket (unfiltered)
  --share-processes        Share enclosing processes and /proc instead of
                           isolating them
  --share-filesystem       Expose the enclosing filesystem read-only, retaining
                           isolated home
  --network-host           Use host networking
  --network-none           Disable networking except private loopback
  --network-private        Use a private pasta network (attempted by default)

Available commands:
  list                     List active workcells in this PID namespace
  enter                    Enter an active workcell
  run                      Run a workcell bwrap session [default command]
```

Default networking tries to set up private networking
but falls back to host networking if its setup fails.
Workcell will print a warning before launching the command.
`--network-private` requires successful private setup.

User and group names are resolved before isolation.
For SSSD and other directory accounts, workcell adds missing entries
for the invoking user and groups to read-only sandbox copies of
`/etc/passwd` and `/etc/group`.

### Starting a workcell

Run `workcell ...` to start a shell, or
`workcell ... -- CMD ARG...` to run a command.

The explicit `run` subcommand is optional:

`$ workcell run --help`

```
Usage: workcell run [--dryrun] [-p|--project DIR[:(ro|rw|O)]] [-H|--home DIR]
                    [-v|--volume SOURCE[:DEST][:(ro|rw|O)]]
                    [-e|--env KEY[=VALUE]] [--wayland] [--x11] [--dbus]
                    [--share-processes] [--share-filesystem]
                    [--network-host | --network-none | --network-private]
                    [[--] CMD ARG...]

  Run a workcell bwrap session [default command]

Available options:
  --dryrun                 Print the bubblewrap command without changing files
  -p,--project DIR[:(ro|rw|O)]
                           Project access (default: rw; :O for temporary
                           overlay; directory defaults to cwd, excluding HOME
                           and ancestors)
  -H,--home DIR            Persistent writable home (created if missing)
  -v,--volume SOURCE[:DEST][:(ro|rw|O)]
                           Extra mount (:O for temporary directory overlay;
                           default: same path, read-only)
  -e,--env KEY[=VALUE]     Set or pass through an environment variable
  --wayland                Expose the Wayland display socket for graphical
                           applications
  --x11                    Expose the local X11 display socket and
                           authentication file
  --dbus                   Expose the desktop D-Bus session socket (unfiltered)
  --share-processes        Share enclosing processes and /proc instead of
                           isolating them
  --share-filesystem       Expose the enclosing filesystem read-only, retaining
                           isolated home
  --network-host           Use host networking
  --network-none           Disable networking except private loopback
  --network-private        Use a private pasta network (attempted by default)
  -h,--help                Show this help text
```

These work also without explicit `run`: the `workcell run --help` output
here is clearer than the earlier `workcell --help` output, which showed
also the other commands available.

In a rootful container where UID 0 lacks `CAP_SYS_ADMIN`, workcell asks
bubblewrap to create a user namespace. The container must permit nested user
namespaces and the required mounts. `--share-processes` can help when only
private PID or `/proc` setup is blocked.

### `list`

Use `workcell list` to list running workcell sessions.

`$ workcell list --help`

```
Usage: workcell list

  List active workcells in this PID namespace

Available options:
  -h,--help                Show this help text
```

### `enter`

Use `workcell enter [--root] [--dryrun] [SESSION] [-- COMMAND ARG...]`
to join a session without sudo.
The session ID is optional when starting a shell;
supply an explicit ID when passing a command.

Ending the original workcell session currently kills sessions entered through
`enter`. Recommend running tmux inside workcell instead, if you need multiple
sessions.


`$ workcell enter --help`

```
Usage: workcell enter [--dryrun] [--root] [SESSION [--] CMD ARG...]

  Enter an active workcell

Available options:
  --dryrun                 Print the entry command without entering
  --root                   Enter as root inside the workcell
  -h,--help                Show this help text
```

## Examples

```shellsession
$ workcell   # open a workcell shell on the cwd
$ workcell --project /path/to/project -- git status
$ workcell -p /path/to/project:ro -- git diff   # read-only project
$ workcell -p /path/to/project:O -- make   # discard project changes on exit
$ workcell --home /path/to/sandbox-home   # persistent home, created if missing
$ workcell -v ~/.gitconfig -- git status    # mount file ro
$ workcell -v ~/.cargo:rw -- cargo build
$ workcell -v ~/.config/cabal -v ~/.cache/cabal:rw -v ~/.local/state/cabal:rw -- cabal build --offline
$ workcell -v /path/to/data:/tmp/data:ro -- ls /tmp/data
$ workcell -v /path/to/data:/tmp/data:O   # temporary writable view of data
$ workcell -e LANG -e MY_VAR=hello -- env
$ workcell --dryrun -- gcc --version
$ workcell --share-processes   # fallback for restricted containers
$ workcell --share-filesystem -- ls /var/log   # expose enclosing filesystem read-only
$ workcell --network-none   # offline, separate loopback network
$ workcell --network-host -- curl localhost:8000   # share enclosing network
$ workcell --wayland gtk4-demo
$ workcell --x11 xterm
```

`:O` requires a directory and bubblewrap with overlay support. Changes to that
mount are discarded when the workcell exits; the source directory stays unchanged.

### Entering an active workcell

From another terminal in the same enclosing environment:

```sh
workcell list
workcell enter                       # use the only active session; starts Bash
workcell enter s123456               # use an ID from workcell list; starts Bash
workcell enter s123456 -- git status
workcell enter s123456 --root        # root inside the workcell
workcell enter s123456 --dryrun
```

The session ID is optional. With one active session, `enter` uses it automatically.
With multiple sessions and terminal input, it shows a numbered menu and prompts
for a choice; press Enter to cancel. Without terminal input, it lists the sessions
and returns an error asking for an ID. With no active sessions, it reports an error.
`--root` and `--dryrun` also work without an ID. Supply an explicit ID when passing
a command.

If the session storage directory is unsafe or unwritable, workcell warns and
runs without session tracking. To enable listing and entry, set `XDG_RUNTIME_DIR`
to a private writable directory and use the same setting from both terminals.

## Requirements
Linux

- bwrap (bubblewrap)
- pasta (passt)
- nsenter (util-linux)

## Installation

workcell is packaged in Fedora Copr:

<https://copr.fedorainfracloud.org/coprs/petersen/workcell/>

## Building

Requires ghc and cabal-install (or stack).

On Fedora: install system deps: `cabal-rpm builddep`.

Then run `cabal install` (or `stack install`)

There is also an extensive testsuite and benchmarking.

## Contributing and development

Workcell is distributed under LGPLv2.1+

<https://github.com/juhp/workcell>

See also the generated [Notes](NOTES.md) for various more details.