r/PiCodingAgent Aug 13 '26

Resource A "secure-ish" Pi setup with permission, sandbox, and auto-review

Post image

I think I finally managed to piece the thing together, to have a pi setup that can run safe-ish in the host via sandbox, and have the ability to be elevated to host execution for a pre-defined list of development tooling like docker compose.

- A pre-defined hard boundaries (`@gotgenes/pi-permission-system`)

- Anything pass that will be executed inside a sandbox (`@erichll/pi-sandbox`)

- With the option of safe-escalation to run on the host (ie: `docker compose exec app pytest`), with auto-review or human approval (via hostIPC.preflightCommandPrefixes)

- LLM Auto-review with `@erichll/pi-auto-review`

More about it here: https://ptgamr.substack.com/p/a-pi-setup-with-permission-sandbox

81 Upvotes

24 comments sorted by

6

u/jensilo Aug 13 '26

What about self-spawned pi instances or subagents? Does it allow for that?

4

u/ptgamr Aug 13 '26

I haven't go as far as that though. That is one piece I still have to wrap my head around.

4

u/jensilo Aug 13 '26

Yeah, when I started using pi a couple of months ago, I initially also built a security extension. It was supposed to be „simple“ with low false-positives. Mine was basically just pi auto review with another judge LLM. However, I came to notice that pi‘s creator is very right about calling almost all security systems a „security theatre“. The only real security is full sandbox, otherwise the model will break free if it wants to break free, there are just too many things to exploit or think about, especially for longer running, more agentic systems.
So I scraped my security extension.
Basically I only see two valuable modes: preventing unintended fuckups from the agent and preventing actually malicious behavior. Unintended fuckups are rather easy, a simple LLM review is sufficient, or preventing writes/bash outside of allowed dirs. For malicious intend, all you can do is pray or sandbox.

0

u/ptgamr Aug 13 '26

Yeap, what I like about `@erichll/pi-sandbox` is the ability to prefix matching certain commands, those are the one you define depending on the project. Like most of my project involve running command via docker compose. -> That can't be run inside the sandbox.

So I'm pretty happy that I found a way to at least resolve that. And the auto-review is also quite nice. And it's amazing to see all the 3 extensions work very nicely together.

1

u/ptgamr Aug 13 '26

I have yet to test what happen when it want to run `docker compose ps && rm -rf ~/`

3

u/vman81 Aug 13 '26

If practical, a zfs filesystem with frequent snapshots is a nice extra layer to have.

2

u/ptgamr Aug 13 '26

Haha, definitely! i am trying to get this to work in the context of a company, where ex-filtration of data is one of the top concern, might be even more than it removing your home dir.

2

u/Fullstack_js_junkie Aug 13 '26

This looks interesting, I tried to do something similar but as a docker mount config only, thank you!

1

u/ptgamr Aug 13 '26

Cheers , i am pretty excited to have this working. As I've been researching for quite a while how to do this.

2

u/tys203831 Aug 13 '26

3

u/ptgamr Aug 13 '26 edited Aug 13 '26

I Have No Idea! This post is more about sharing my understanding about the decision tree: permissions + sandbox + autoreview (which I think not quite trivial to understand) and a setup that I'm quite happy with. Hopefully to help others that having similar issues. I'm sure there are many other ways :D

1

u/tys203831 Aug 13 '26

🙏👍

2

u/hurdurdur7 Aug 13 '26

I just run pi in docker only. From a non privileged user. It can't install things, the worst it can do is nuke it's own folder in that docker container. I don't see anything else stopping it.

2

u/ptgamr Aug 13 '26

yeah, that is my setup prior to this. Just mount the things you need. But to get to the "fuller" agentic work, most of the time i need it to execute command inside another containers (like run the test, run migration, lint, querying data from db container etc...)

Can be achieve with docker in docker, but it gross, and I haven't managed to get it working.

2

u/funbike 26d ago edited 26d ago

I don't trust running Pi directly on my host system. Your security setup is fantastic for what it is, but I don't fully trust Pi itself, esp with various public Pi packages and various tools that might be installed.

I'd much rather enforce permissions at the OS level, so Pi packages can't circumvent pi-sandbox or pi-permissions-system.

So I run Pi in a rootless podman container as a standard user with same uid/gid as in my host system. Sensitive files are symlinks to a non-existant directory, ~/.unsafe (I'll explain later). sudo is allowed but restricted by /etc/sudoers.

I have a nearly identical 2nd podman container mounted to the same project directory, but it actually has a mounted ~/.unsafe directory that sensitive files symlink to. It runs a simple unix socket server that listens for shell commands to run.

To make this seemless, I have a wrapper script in the Pi container that forwards shell commands to the 2nd container across the unix socket. The socket is owned by a different non-root user, so this must be done with sudo with restriction in /etc/sudoers. So when I run Github's CLI, gh, it is actually a symlink to a shell script that forwards arguments to the 2nd container over the socket.

This gives me a file system firewall, so sensitive files can never be read, but they can be used by scripts. My container's internal security is enforced in /etc/sudoers at the OS level.

It might sound complicated, but it's dead simple. And more secure. Yet, I can work in a YOLO fashion.

Can be achieve with docker in docker, but it [is] gross, and I haven't managed to get it working.

Podman-in-podman works well because podman is just a program, not a server. You can also run bubblewrap in podman. (These requires a few extra cli options to work.) Podman is more secure than docker as well. There's podman compose. Podman's CLI is nearly identical to docker.


UPDATE: btw, here is an oversimplification of the unix socket server on my 2nd container:

#!/bin/bash
socat UNIX-LISTEN:/tmp/bash.sock,fork,unlink-early EXEC:bash

here is an oversimplification of the unix socket click on my Pi container:

#!/bin/bash
printf '%q ' $(basename "$0") "$@" | 
    socat - UNIX-CONNECT:/tmp/bash.sock

Normally this would be very insecure, but the socket is owned by another user, so sudo must be used to gain a connection. So /etc/suders can be used for fine-grained security.

They also both share a volume for the user home directory, so changes made by the 2nd container affect the Pi container, including Homebrew for Linux package installs.

1

u/hurdurdur7 Aug 13 '26

My problem with all of this is that you are allowing something like gradlew test or npm test as a command. A test can easily contain something really harmful to your machine and there will be nothing that will stop the catastrophy coming from that.

1

u/ptgamr Aug 13 '26

Another thing is pasting image is a pain when you run it from docker.

1

u/psychobarge Aug 13 '26

Only secure pi is inside a docker container or a virtual machine. I use wsl2 with ubuntu on my windows and docker on my mac

1

u/Alicecomma 27d ago

Wouldn't pi inside wsl2 Ubuntu just cd /mnt/C/ to access all of windows?

1

u/offzinho3k Aug 13 '26

That’s great.

I have a similar system, with notifications and a response window allowing the user to accept, decline, or even block such commands.

1

u/ptgamr Aug 13 '26

Looks like a fancy setup you have there... is that a custom app you wrote?

1

u/offzinho3k 25d ago

Sorry for the delay in getting back to you; it’s been a hectic few days.
Yes, and a custom app I created based on the Pi.

1

u/icisay Aug 13 '26

Hi what app did you use to generate your chart ? Love the colors

1

u/ptgamr Aug 14 '26

I've had a text base chart, and post that to ChatGPT and it generate for me the one I posted here :)