r/opencodeCLI • • 19h ago

Best Practice / Guide for setting up OpenCode in a Docker container or sandbox?

My Ideal setup would be something like - OpenCode using VSCode with Git, node, python, C++ and Rust all installed and ready to use, plus my skills, scripts and MCP's. All in one docker sandbox, setup remains consistent every time I launch.

Can I use the GUi with a docker sandbox?

Is there a guide for this? What would you do differently?

12 Upvotes

8 comments sorted by

3

u/4SubZero20 18h ago

I do this. I didn't follow any guide or best practices on the Internet.

I just read about people on the Internet complaining that their Agent deleted important directories and sometimes even root. I knew I didn't want that; and that was the motivation I needed to run my agents/work in Docker.

Now I also believe in first trying the tools you have/know, before reaching for something new.

This lead me to just create a normal Dockerfile and install everything I want/need in my "development environment" (git, node, opencode, openchamber, Claude, github cli, etc.). I even call my image "dev-env".

Then I have a bash method (that starts a docker image/container) saved in my (host) .bashrc that I can call when in terminal and it drops me in a running container.

I have a secondary method in my .bashrc that attaches to the same container, so that I can additional in the container if/when needed and I'm not confined to 1 terminal.

Then in my containers' .bashrc, I have methods to start the OpenCode (V2) server, along with Openchamber and a few aliases so I can type oc instead of opencode --server http://127.0.0.1:4098

Note: In these steps, there is no GUI. This is a terminal first workflow on Linux (will probably work on Mac as well)

2

u/ExternalStaff 18h ago

Thanks. I'm going to have to read up on this as I'm completely new to docker.

3

u/Hedshodd 18h ago

On macOS you can use some lightweight VM like Lima to get a similar setup. That’s what I currently use for work. It’s neat because it handles port forwarding and stuff like that for you fairly easily.

1

u/d32dasd 15h ago

Docker is not enough. It can be escaped with easily.

2

u/Winston-Turtle 13h ago

i use docker sandboxes, it’s pretty easy 

1

u/Much_Programmer_5688 13h ago

putting all those toolchains in one image is gonna make the build huge tbh. youd probably have an easier time splitting the languages into project-specific containers and just mounting your config directory as a shared volume.

1

u/The-Phantom-kid 8h ago

You can use bwrap (bubble wrap) on Linux for a lightweight alternative to docker sandbox. You can bind all your skills/config and any dev tools you have installed and the agent can use them. Didn't test it with the GUI though.

1

u/NecessaryRadio5040 6h ago

The ideal setup depends on your personal preferences I think. Personally to avoid the overhead of vms and containers - I use local host confinement with nono configured so it can access git, docker, clipboard and such but only have access to files within the directory the sandbox was run from and not access to files outside except for /tmp/ that it can use to test things.

The two options that fit your requirement for docker (or at least harder isolation) are:

When you say gui you mean the opencode GUI?

There is not much out there in terms of guides but there is this blog post that goes through a few sandbox options and setup