|
| 1 | +# Sandboxing Coding Agents |
| 2 | + |
| 3 | +You can run coding agents like [Claude Code](https://code.claude.com/docs/en/overview), [OpenCode](https://opencode.ai/), and [Amp](https://amp.dev/) inside Slicer VMs. |
| 4 | +This page applies to both Slicer for Linux and Slicer for Mac. |
| 5 | + |
| 6 | +Running an agent inside a VM means you don't need to grant broad permissions on your host CLI. The agent gets its own kernel and filesystem, and can't touch your SSH keys, cloud credentials, or browser sessions. |
| 7 | + |
| 8 | +## `slicer workspace`: generic workspace runner |
| 9 | + |
| 10 | +`slicer workspace` is a generic command that bootstraps a fresh VM for your current project workspace. It copies your working directory into the VM and drops you into a shell so you can run a tool of your choice. |
| 11 | + |
| 12 | +Use it when you want one-VM-per-task behavior without being tied to a specific agent binary. For example, use it for: |
| 13 | + |
| 14 | +* trying out a new tool against a codebase |
| 15 | +* running a custom script-based agent |
| 16 | +* reproducing task-specific work in a disposable environment |
| 17 | + |
| 18 | +Because it is generic, it’s a good fit when the built-in `slicer claude`, `slicer opencode`, etc. shortcuts don’t match your exact workflow. |
| 19 | + |
| 20 | +## Automated agent and sandbox launches |
| 21 | + |
| 22 | +Slicer has a number of experimental commands that do the following: |
| 23 | + |
| 24 | +* Boot a new VM |
| 25 | +* Copy the current directory to the VM in the same relative path |
| 26 | +* Install the specified AI agent and copy in its config/auth files |
| 27 | +* Launch the agent in a shell (`slicer vm shell`) |
| 28 | + |
| 29 | +Available agent commands: |
| 30 | + |
| 31 | +* `slicer workspace` |
| 32 | +* `slicer amp` |
| 33 | +* `slicer copilot` |
| 34 | +* `slicer codex` |
| 35 | +* `slicer claude` |
| 36 | +* `slicer opencode` |
| 37 | + |
| 38 | +If your agent (for example, Pi or Hermes) is not listed above, request support in the Discord, or use `slicer workspace` and install and configure your agent via a bash script or userdata. |
| 39 | + |
| 40 | +To launch a new Slicer VM for Claude: |
| 41 | + |
| 42 | +```bash |
| 43 | +mkdir -p ~/dev/ |
| 44 | +cd ~/dev/ |
| 45 | +git clone --depth=1 https://github.com/alexellis/arkade |
| 46 | + |
| 47 | +cd arkade |
| 48 | + |
| 49 | +slicer claude . |
| 50 | +``` |
| 51 | + |
| 52 | +When launching a VM for a coding agent, you can specify: |
| 53 | + |
| 54 | +* `--tmux=none` - launch the agent directly in the shell |
| 55 | +* `--tmux=local` - launch a shell using tmux on the host (requires `brew install tmux` on macOS) |
| 56 | +* `--tmux=remote` - launch a shell using tmux on the VM |
| 57 | + |
| 58 | +Tmux is a time-tested terminal tool and ideal for running processes in the background, and reconnecting to them later. |
| 59 | + |
| 60 | +## Install agents manually |
| 61 | + |
| 62 | +Shell into your VM and install agents with [arkade](https://github.com/alexellis/arkade): |
| 63 | + |
| 64 | +```bash |
| 65 | +slicer vm shell slicer-1 |
| 66 | + |
| 67 | +# Install Claude Code |
| 68 | +arkade get claude --path /usr/local/bin |
| 69 | + |
| 70 | +# Install OpenCode |
| 71 | +arkade get opencode --path /usr/local/bin |
| 72 | +``` |
| 73 | + |
| 74 | +Both binaries are installed into `/usr/local/bin` inside the VM. They persist across reboots if your base VM is persistent. |
| 75 | + |
| 76 | +## Authenticate |
| 77 | + |
| 78 | +### Claude Code with an API key |
| 79 | + |
| 80 | +Set the `ANTHROPIC_API_KEY` environment variable inside the VM: |
| 81 | + |
| 82 | +```bash |
| 83 | +export ANTHROPIC_API_KEY=sk-ant-... |
| 84 | +``` |
| 85 | + |
| 86 | +Add it to `~/.bashrc` to persist across sessions: |
| 87 | + |
| 88 | +```bash |
| 89 | +echo 'export ANTHROPIC_API_KEY=sk-ant-...' >> ~/.bashrc |
| 90 | +``` |
| 91 | + |
| 92 | +Then run Claude Code: |
| 93 | + |
| 94 | +```bash |
| 95 | +cd /home/ubuntu/host/code/my-project |
| 96 | +claude --dangerously-skip-permissions |
| 97 | +``` |
| 98 | + |
| 99 | +Inside the VM, `--dangerously-skip-permissions` is acceptable because the VM is the sandbox. |
| 100 | + |
| 101 | +!!! note "Claude Max plan" |
| 102 | + The Claude Max subscription uses OAuth-based authentication. Run `claude` inside the VM and follow the interactive login flow. The auth token is stored inside the VM and does not affect your host. |
| 103 | + |
| 104 | +### OpenCode |
| 105 | + |
| 106 | +Authenticate with your provider of choice: |
| 107 | + |
| 108 | +```bash |
| 109 | +opencode auth login --provider github --token <your-github-token> |
| 110 | +``` |
| 111 | + |
| 112 | +The auth config is stored at `~/.local/share/opencode/auth.json` inside the VM. |
| 113 | + |
| 114 | +## Linux-specific workspace details |
| 115 | + |
| 116 | +On Slicer for Linux, use the workspace mounting pattern defined for your host/group and the normal `slicer vm cp` flow for file movement. |
| 117 | + |
| 118 | +Use: |
| 119 | +- your host filesystem access model (from your host/group config) |
| 120 | +- `slicer vm cp` for explicit copies into and out of ephemeral VMs |
| 121 | + |
| 122 | +## Run headless agents non-interactively |
| 123 | + |
| 124 | +For one-off and automated tasks, launch a sandbox instead of using your persistent VM: |
| 125 | + |
| 126 | +```bash |
| 127 | +# Launch a sandbox |
| 128 | +slicer vm launch sbox |
| 129 | + |
| 130 | +# Copy a repo in |
| 131 | +slicer vm cp ./my-project sbox-1:/home/ubuntu/my-project |
| 132 | + |
| 133 | +# Run the agent |
| 134 | +slicer vm exec --uid 1000 --cwd /home/ubuntu/my-project sbox-1 -- \ |
| 135 | + claude --dangerously-skip-permissions -p "Write tests for main.go" |
| 136 | + |
| 137 | +# Copy results out |
| 138 | +slicer vm cp sbox-1:/home/ubuntu/my-project ./my-project-result |
| 139 | + |
| 140 | +# Delete when done |
| 141 | +slicer vm delete sbox-1 |
| 142 | +``` |
| 143 | + |
| 144 | +The sandbox has its own kernel and filesystem. If the agent does something unexpected, delete it and start fresh. |
| 145 | + |
| 146 | +## Next steps |
| 147 | + |
| 148 | +- [Sandboxes](/mac/sandboxes) - more on launching and managing ephemeral VMs |
| 149 | +- [Headless OpenCode on Slicer for Linux](/examples/opencode-agent) - one-shot agent execution via userdata and the exec API |
| 150 | +- [Headless Cursor CLI on Slicer for Linux](/examples/cursor-cli-agent) - running Cursor's CLI agent headlessly |
| 151 | +- [Trying Claude Code with Ollama](https://slicervm.com/blog/trying-claude-code-with-ollama) - using Claude Code with a local LLM backend |
0 commit comments