Rewiring

Sandboxing a bot II - dev containers

I recently posted about how I use containers to sandbox AI harnesses like Copilot CLI. That's worked out beautifully, but as I've been looking into dev containers I put two and two together and thought, why not put the bot inside the dev container? After all, it's just a CLI that needs access to the same build/debug/dev tools I normally do and not much more.

Here's the general approach for GH Copilot, and the same should work for claude/pi/whatever.

Let's assume a minimal dev container setup like this sample. Expose the GH_TOKEN env var in e.g an .env file you point to in the docker-compose.yml:

env_file:
  - path: ./userconfig/.env
    required: false  

and then in the main Dockerfile do (assuming Node is available)

RUN npm install -g copilot

Then... that's it. Within the dev container you have a fully functional, pretty nicely sandboxed harness that only has access to what it needs to run, develop and debug the system. Assuming you have the devcontainer CLI available, you can jump into a session with devcontainer exec copilot.

You can also mount e.g. ~/.agents in the devcontainer.json file:

  "mounts": [
    "source=${localEnv:HOME}/.agents,target=/root/.agents,type=bind,readonly"
  ],

And pass this as an env var:

COPILOT_CUSTOM_INSTRUCTIONS_DIRS="/root/.agents"

allowing the bot to see any custom instructions, skills, agent definitions you have on the host.

One thing this approach misses is referencing other projects on the host directly. I frequently do check out how this is implemented at @/root/work/whatever which cannot be done from the dev container. The bot could be given access to the referenced repo and use e.g. some MCP action to see what's happening, but that seems a waste compared to just file lookups.

For me at least it seems best to have both - a host wide sandbox for generic work and project specific small dev containers.

As a bonus, this can be easily added to sidekick.nvim:

require("sidekick").setup({
  cli = { 		
    tools = { 		
      devcontpilot = { 		
	cmd = { "devcontainer", "exec", "copilot" }
      }

Thoughts, comments? Send me an email!

#ai #tech