Sandboxing
To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.
Thinking more about #324, especially for shell commands, I think preventing all unreasonable commands isn't really possible without manual review. Sandboxing would be much better. Claude has /sandbox, and it looks like people are using all sorts of different ways for sandboxing opencode and other harnesses (using incus, bubblewrap, docker, etc.). Most of them seem significantly more painful to setup than something builtin.
I don't know that it actually makes sense to have something directly part of eca, though I am wondering if anyone has any recommended method to use with eca. Is anyone here doing some sort of sandboxing with eca?
I don't think anyone is doing that, but maybe @zikajk has anything in mind. I feel like it's more worth it to invest on permissions improvements if any than sandboxing but I may be wrong as I'm no sandbox user.
No idea how to do something like this in IDE based coding agent.
I feel like it's more worth it to invest on permissions improvements if any than sandboxing but I may be wrong as I'm no sandbox user.
Permissions can prevent some bad or mistaken commands, but they can't actually prevent anything malicious. There will always be a way to workaround any permission system. Sandboxing would be more reliable, and you don't have to worry as much about tweaking permissions. I think both make sense, though it's easier for eca itself to do something about the permissions part.
No idea how to do something like this in IDE based coding agent.
Why would it be different from any other coding agent? I think all the same methods should work. The server is what is actually handling everything including the tool calls, right?
What I'm wondering is what the best, simplest method to use with eca is and what eca can do to make sandboxing it as painless as possible.
Using incus or containers seems like too much of a pain for me right now, but using a sandboxing tool like bubblewrap or firejail or whatever seems simple enough. Using bubblewrap already appears to work fine. I've added a rule to let it know that it is sandboxed and can't access external directories so it doesn't get confused. I'm also having to advise eca to set the ECA_PROJECT_DIR variable before starting since there's no way to pass dynamic arguments with eca-extra-args, but it works okay.
(must not use --unshare-pid)
bwrap \
--ro-bind /usr /usr \
--ro-bind /lib /lib \
--ro-bind /lib64 /lib64 \
--ro-bind /bin /bin \
--ro-bind /etc/resolv.conf /etc/resolv.conf \
--ro-bind /etc/hosts /etc/hosts \
--ro-bind /etc/ssl /etc/ssl \
--ro-bind /etc/passwd /etc/passwd \
--ro-bind /etc/group /etc/group \
--bind "$ECA_PROJECT_DIR" "$ECA_PROJECT_DIR" \
--bind "$HOME/.emacs.d" "$HOME/.emacs.d" \
--bind "$HOME/.config/eca" "$HOME/.config/eca" \
--bind "$HOME/.cache/eca" "$HOME/.cache/eca" \
--tmpfs /tmp \
--proc /proc \
--dev /dev \
--share-net \
--die-with-parent \
--new-session \
--chdir "$ECA_PROJECT_DIR" \
--ro-bind /dev/null "$ECA_PROJECT_DIR/.env" \
~/.emacs.d/eca/eca "$@"
Claude code includes bubblewrap support, but bubblewrap only works on linux. Since the method is going to be different for the person and OS, it may not make sense to include anything in ECA, but maybe a wiki would be useful?
At least it would be useful if ECA documented in one place a list of all the directories it reads/writes. Did I miss any?
Good research @noctuid!
Claude code includes bubblewrap support, but bubblewrap only works on linux. Since the method is going to be different for the person and OS, it may not make sense to include anything in ECA, but maybe a wiki would be useful?
Yeah agree, I don't see much to do on eca side besides maybe a doc page explaining about how to use sandbox with ECA via bubblewrap or something?
At least it would be useful if ECA documented in one place a list of all the directories it reads/writes.
Not sure I got that, ECA already can read/write in any directory of your filesystem, the only thing is whether it will ask to do it before doing it, the permissions follow by agents, the 2 built-in primary agents allow reading without asking any file inside the workspace root, but files outside it will ask, while write will ask even for files inside the project (more details here)
Yeah agree, I don't see much to do on eca side besides maybe doc page explaining about how to use sandbox with ECA via bubblewrap or something?
I think that would be useful or a github wiki where users could add examples.
Probably there will be more generic solutions in the future. Looks like there are a bunch of different methods people are using right now like docker sandbox, incus (e.g. code-on-incus), wasm sandboxing (ironclaw is doing this), etc. I don't know if it would be easily possible to run just eca in docker sandbox. Docker sandbox doesn't support linux, so I haven't tested it, but it is focused on coding agents.
What claude code does right now seems the simplest for eca currently: bubblewrap on linux and wsl2 and seatbelt/sandbox-exec on macos.
Not sure I got that
What I meant by this is what directories it needs to function in general: where it reads configuration, stores sessions, where it caches anything, etc. I saw .config/eca and .cache/eca on linux (and then .emacs.d for emacs-eca). Not sure if there are any other directories that vscode, neovim, etc. users or everyone would need to allow, which is what I wanted to check. Some of the directories claude code needs whitelisted are not immediately obvious, not sure if that's the case with eca.
@noctuid we already have a user examples page at https://eca.dev/config/examples/ maybe we could add there?
What I meant by this is what directories it needs to function in general
Ah got it, yeah, ECA does have a --pure flag but probably not useful for users, so it only relies on ~/.config/eca and ~/.cache/eca really, and clients just use their editors folders to download the eca server binary to then start.
For eca-emacs it might also be possible to use TRAMP mode with eca running on the remote.
I just came across this. https://github.com/anthropic-experimental/sandbox-runtime
I just came across this. https://github.com/anthropic-experimental/sandbox-runtime
Yeah, I'd personally rather use bubblewrap directly than anthropic's wrapper around it though. Seatbelt/sandbox-exec is also deprecated, though don't know if it will actually be removed any time soon. I am probably switching from bubblewrap to gondolin personally, but I have not tested if it can easily work with eca yet.
I've experimented with ECA and jai sandboxing tool (https://jai.scs.stanford.edu/) which is a bit like bubblewrap "pre-configured" for AI coding agent usage. It allows making only the working directory and specified dirs visible to the "jailed" process running as unpriviliged user, hiding user env vars, processes and other stuff. Linux only but I saw mention of some MacOS port linked on their site.
For ECA I ran it through wrapper script like this to be able to wrap eca process:
#!/bin/bash
# -D doesn't expose $CWD (home by default)
# --unsetenv='*' hides all environment variables
# --setenv TERM keeps basic terminal hotkeys working if required
# -d exposes specific directory
exec jai -j eca \
-D \
--unsetenv='*' \
--setenv TERM \
-d /home/user/.config/eca/ \
-d /home/user/.emacs.d/ \
-d /home/user/dev/jail/ \
-d /home/user/.cache/eca/ \
/home/user/.emacs.d/eca/eca "$@"
Using Emacs config for Eca client:
(setq eca-custom-command '("/home/user/.emacs.d/eca/ecajail" "server"))
(setq eca-send-process-id nil)
The ECA's parent process monitor was tripping out and closing the server after startup as jai hides the PID's so I turned it off by setting the process-id to nil.
For improving this, @ericdallo suggested eca-process-wrapper-function on Clojurians Slack, which could avoid having to use such wrapper shell script as eca-custom-command.. there's new docs on that https://github.com/editor-code-assistant/eca-emacs#sandboxing.
I didn't look into adding Emacs buffers' directories automatically into jai's whitelist (set once on process startup), but for now I just keep the projects it can access in the ~/dev/jail/ directory.
Maybe the ECA-accessible folders could be managed client side so that client would reload the jailed ECA server with new directory permissions on the fly, and the restarted server would restore the session without user noticing if clients can reconnect it smoothly.
From my point of view you want to have tools available to the client. I was thinking something like a container that exposed the project source tree but hide .git and maybe only exposed one build directory. Then the agent could be pretty free to mess about in the container and the worst it could do (baring trying to actively jailbreak its bounds) is delete the code which would be restorable via version control by the user.
I had been looking at https://github.com/Gerharddc/litterbox but I'm not sure it has quite the granularity for exposing $HOME I would need.
Of course that doesn't stop the agent going wild with API keys and network services.
sandboxing with containers feels like the worst of both worlds (comparably bad convenience and security).
Of course that doesn't stop the agent going wild with API keys and network services.
Use something with secret injection if you care about that (nono.sh, microsandbox, etc.).
hide .git
Think this is overkill. Makes things less useful and you could either restore from a remote or use one of the sandboxes that allow rollback (e.g. nono).