Since I started using coding agents I’ve been annoyed that I didn’t have a good solution to limit what they can access. They all claim to have some sort of sandboxing system built in, but it’s all just a charade. How good can the sandbox be if the agent itself controls it? Also, the thing where the agent constantly asks for permission to run some obscure 500-character command, who reads those commands? Who understands them fully? It just turns into a constant stream of approve-approve-approve actions from the user, without full understanding, eventually just accepting the agent’s insistence on using “auto mode”, leaning even more into the “solution” that the agent polices itself. It’s all a very silly charade of security. A lot of people also seem to run agents with all the fake security turned off, which seems like an even sillier idea. Stories of people losing important files because of out-of-control agents pop up every now and then.
So, I started exploring what I could do to improve on the situation. I didn’t do a lot of investigation of existing solutions, because nothing I had seen seemed appealing to me. I knew I didn’t want a short-lived environment for just the agent. What use is sandboxing the agent if the code it writes runs on your machine anyway? I think we can all come up with ideas for how that could be abused by a creative agent. Ideally I would get to continue work as I normally would, with a persistent environment and without having to build a bunch of random Docker images. I use devenv.sh so I have dependency management and services running covered already. It’s based on Nix and is a comprehensive solution to everything from software packaging to configuration management (even Docker image building).
I worked on this in September and October (2026), and now it’s almost the middle of November, so the exact timeline of what I explored and how things came together is not completely clear to me anymore. This is more of a fuzzy list of my thinking and the things I did. I ruled out Docker and Podman early because I wanted proper separation, sandboxing, between different projects, and on Mac, Docker and Podman use a Linux virtual machine that then runs the containers inside of it, all sharing the one VM’s kernel. That doesn’t sound like a good sandbox. I also don’t like that using containers feels like an ephemeral thing, compared to a proper VM. I know all these complaints are solvable, but a solution that requires fewer problems to be solved is worth exploring first imo. I don’t mean to hate on containers here, I have used them a lot for deploying things, they definitely have their place, but for long-lived development environments they seemed like the more annoying and complicated choice. I do realise I have my own biases and I might well be wrong here, I’m just a guy messing around with computers for fun!
So, that left me with virtual machines. There are a bunch of ways to run virtual machines on Mac. I spent a lot of time exploring if I could use Lima-managed VMs, and learned about all sorts of things along the way. I realised a VM with a filesystem shared with the host left too many holes open. I wanted a proper sandbox, and Lima just did too many things. For instance it likes to share home directories between host and VM, and it’s hard/impossible to fully turn such features off.
In the process of exploring Lima solutions I stumbled upon the sandbox-exec tool, which lets you put restrictions on
what an executable is allowed to do. In typical Apple fashion, the sandbox-exec tool has been deprecated for years
even though they haven’t released a replacement. But the underlying tech is still supported and used by other parts of
Apple’s stuff. It’s still the standard sandboxing tool on macOS.
Somewhere around here I also realised it would be neat to have the aforementioned devenv manage the sandboxed VM. I vibed up a devenv module that fully managed the VM through Lima, it installed the repo into the VM and did all sorts of integrations. Luckily I didn’t spend too long on this, because I realised it was a dead end. It turned out way too complicated and hard to understand and use. How would branching work? Should changing branch on the host change branch inside the VM? What happens if the user wants to work on multiple projects inside the one VM? It was clear it was a bad idea.
As I said earlier, Lima did things I didn’t want it to do, that went against sandboxing. But it also had some really
good ideas, like the ssh config integration where it produces an ssh config file for each VM. The user can include any
existing or future VM in their own ssh config by just adding a single line in their ~/.ssh/config, which lets them ssh
into the VMs by their VM name (as opposed to having to specify host and port, or set up the alias manually). I stole
that idea for my project.
Through Lima I learned about krunkit, a new VM runner for macOS that advertises itself as being lightweight, and being able to give back memory the guest no longer uses to the host (that turned out to be only partially true, but work is ongoing on that, and my project integrates a patch that makes that claim fully true). Those two things, it being lightweight, and giving back RAM are why I went with it over the more established vfkit.
What I ended up building, with the help of Claude Code, is a supervisor that runs krunkit VMs, contained by
sandbox-exec. Each project gets its own full VM. There’s no filesystem sharing between the host and VM, and all
network access goes through a proxy. The proxy (smokescreen) and the user-space
networking (gvproxy) between the host and VM are also sandboxed by
sandbox-exec. The user controls what is accessible through the proxy and can also choose to expose ports into the VM,
and out from it. The VM runs NixOS, the Nix Linux distribution. The OS is fully declarative and the
configuration is committed in the repo beside the devenv. It runs as a devenv service, which is quite nice if you
already use devenv, and opens up possibilities for extending how the VM can be accessed and what it can access. It’s a
pretty nice fit for this sort of thing.
Having abandoned my earlier attempt where devenv tightly controlled how the VM was used, I went with very loose coupling. There is nothing forcing the user to use the devenv that defines the VM inside the VM. It can be done, and I do it in most of my projects, but it does not need to work like that. The user can have a dedicated devenv project whose only purpose is to run a VM, and then run some other project(s) inside the VM. That will be the preferred way in some circumstances, like when you really want to enforce the separation in a way where the project that should be sandboxed never even touches the host, or where you for some reason don’t want to contribute back the sandbox-vm configuration to the project you’re working on.
If it sounds interesting to you, please go ahead and take a look at devenv-sandbox-vm. It’s only for macOS for now. There are more features and details I haven’t mentioned here so go to the readme and the docs for more info. It’s early days, but I’m using it myself every day and fixing bugs as they pop up. I’m interested in what ideas and suggestions other people have for the project. I think a tool like this would be useful outside of devenv as well, and I may pick up working on that later. I would also be interested in running sandboxed macOS VMs in this way.