A secure, containerized development environment for AI-assisted coding with OpenCode
OpenCode Box provides an isolated Docker environment where you can safely work with AI-powered development tools while keeping your host system secure. It automatically sets up a complete development environment with your project, credentials, and OpenCode configurations.
Install OpenCode Box globally via NPM:
npm install -g opencode-box-
Navigate to any Git repository:
cd /path/to/your/git/project -
Launch OpenCode Box:
opencodebox
That's it! OpenCode Box will automatically:
- π³ Build the Docker image (if not already built)
- π Securely forward your SSH/Git credentials to the container
- βοΈ Copy OpenCode configurations (
~/.local/share/opencodeand~/.config/opencode) - π Clone the current repository inside the container
- πΏ Checkout to the current branch from your host machine
- π€ Start OpenCode in the isolated environment
OpenCode Box supports three different workspace modes to suit your needs:
Isolated development environment - Clones repository inside container
opencodebox --gitcheckout- β Interactive terminal session
- π SSH credentials required
- π¦ Dedicated workspace volume
- π Automatic cleanup on exit
Read-only workspace mounting - Direct access to your current files
opencodebox --mount-ro- π Code examination only
- π« No file modifications allowed
- β‘ No SSH requirements
- π Direct workspace mounting
Read-write workspace mounting - Edit files directly in your workspace
opencodebox --mount-rw- βοΈ Direct file editing
- πΎ Changes saved to host filesystem
- β‘ No SSH requirements
- π Direct workspace mounting
Interactive Shell Access Get a shell in an existing gitcheckout container for debugging:
opencodebox --gitcheckout --itForce Image Rebuild Update OpenCode and dependencies to latest versions:
opencodebox --gitcheckout --rebuildMultiple Mount Instances Run multiple containers with different workspaces:
# Terminal 1
cd ~/project-a
opencodebox --mount-ro
# Terminal 2
cd ~/project-b
opencodebox --mount-rwConsistent Naming for GitCheckout
- Container name:
opencode-box-<project>-<path-hash> - Reusable across sessions
- Example:
opencode-box-my-app-a1b2c3d4
Unique Naming for Mount Modes
- Container name:
opencode-box-<project>-<path-hash>-<timestamp> - Multiple instances allowed
- Example:
opencode-box-my-app-a1b2c3d4-1699123456789
| Mode | Description | SSH Required | Interactive | Container Name |
|---|---|---|---|---|
--gitcheckout |
Clone repository inside container | β Yes | β Yes | opencode-box-<project>-<hash> |
--mount-ro |
Mount workspace as read-only | β No | β No | opencode-box-<project>-<hash>-<timestamp> |
--mount-rw |
Mount workspace as read-write | β No | β No | opencode-box-<project>-<hash>-<timestamp> |
| Option | Description | Usage |
|---|---|---|
--it |
Get interactive shell in existing gitcheckout container | opencodebox --gitcheckout --it |
--rebuild |
Force rebuild Docker image (removes existing) | opencodebox --gitcheckout --rebuild |
--help, -h |
Show help message | opencodebox --help |
--version, -v |
Show version information | opencodebox --version |
# Basic usage
opencodebox --gitcheckout
# Read-only examination
opencodebox --mount-ro
# Direct editing
opencodebox --mount-rw
# Force rebuild with latest dependencies
opencodebox --gitcheckout --rebuild
# Get shell in running container
opencodebox --gitcheckout --it
# Multiple mount instances
opencodebox --mount-ro & # Terminal 1
opencodebox --mount-rw # Terminal 2
# Rebuild and mount
opencodebox --mount-ro --rebuild- Node.js: v16.0.0 or higher
- npm: v7.0.0 or higher (comes with Node.js)
- Docker: v20.10.0 or higher (installed and running)
- Git: v2.25.0 or higher (configured on host machine)
For --gitcheckout mode:
- SSH Agent: Must be running with Git credentials loaded
- Git Configuration: User name and email configured globally
- Repository Access: Valid SSH key or credentials for target repository
For --mount-ro and --mount-rw modes:
- No SSH Requirements: Works with any local Git repository
- Git Repository: Must be run from inside a Git project
- File System: Direct access to your workspace files
- OpenCode CLI: Pre-installed on host machine for easier authentication setup
- Docker Compose: v2.0.0 or higher (for advanced configurations)
SSH agent is required for:
- π SSH-based Git URLs (
git@github.com:user/repo.git) - π Private repository access
- π SSH-authenticated Git operations
Setup SSH Agent:
# Start SSH agent
eval "$(ssh-agent -s)"
# Add your SSH key (replace with your key path)
ssh-add ~/.ssh/id_rsa
# Verify key is loaded
ssh-add -lEnsure Git is properly configured:
# Check current configuration
git config --global user.name
git config --global user.email
# Set if not configured
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"Verify Docker is running:
# Check Docker status
docker --version
docker info
# Test Docker functionality
docker run hello-world# Navigate to any Git project
cd ~/my-projects/react-app
opencodebox# Works with monorepos
cd ~/my-projects/large-monorepo
opencodebox
# Works with private repositories
cd ~/my-projects/private-enterprise-app
opencodebox
# Works with different Git providers
cd ~/my-projects/gitlab-project
opencodeboxThe OpenCode Box container includes:
- Base Image:
node:20-alpine(lightweight and secure) - OpenCode CLI: Globally installed via
npm install -g opencode-ai - Non-root User: Secure user environment without sudo privileges
- Isolated Network: Container networking for security
- Volume Mounts: Project files and configuration directories
SSH Key Not Found:
# Ensure SSH agent is running and key is added
ssh-add -lDocker Permission Denied:
# Add user to docker group (Linux)
sudo usermod -aG docker $USER
# Then logout and login againGit Authentication Failed:
# Test SSH connection to GitHub
ssh -T git@github.comOpenCode Configuration Missing:
# Verify OpenCode config exists
ls -la ~/.config/opencode
ls -la ~/.local/share/opencodeContainer Not Found for --it Flag:
# Error when trying to get shell in non-existent container
opencodebox --gitcheckout --it
# Solution: Start container first
opencodebox --gitcheckoutMultiple Container Name Conflicts:
# Check running containers with same project
docker ps --filter "name=opencode-box-my-project"
# Solution: Use different timestamps or stop existing container
docker stop opencode-box-my-project-a1b2c3d4Mount Mode Permission Issues:
# Check file permissions on mounted workspace
ls -la /path/to/your/project
# Solution: Ensure proper ownership and permissions
sudo chown -R $USER:$USER /path/to/your/project- Workspace Modes: Implemented
--mount-ro,--mount-rw,--gitcheckoutmodes - Container Management: Smart naming with project-based identifiers
- Interactive Shell Access:
--itflag for existing gitcheckout containers - Resource Optimization: Conditional TTY allocation and SSH mounting
- Volume Mounting: Mount specific local folders with absolute paths for document/image sharing
- Multi-Platform Support: Enhanced support for Windows and Linux environments
- Performance Optimization: Faster container startup and build times