Skip to main content
This guide installs OpenCode in a microVM and opens its terminal UI in a project mounted from your host. OpenCode edits the source checkout directly while its tools and dependencies stay inside the sandbox.

Run OpenCode

1

Start OpenCode

Replace ./my-project with the project directory you want OpenCode to work on:
The first run downloads the package and may take a couple of minutes. OpenCode should render its prompt and offer /connect for provider setup. Its XDG configuration, provider connections, and session data live on the sandbox’s 4 GiB root disk and remain available when the sandbox stops and starts.
For an isolated workspace, or when using microsandbox cloud, replace --mount-dir ./my-project:/workspace:rw with --copy-dir ./my-project:/workspace. To try the TUI without a project, use --mkdir /workspace instead.
2

Start another session

After leaving OpenCode, return to the same sandbox and workspace with:
3

Verify the installation

Exit the TUI, then run:
The pinned example prints 1.18.4.
4

Review or export changes

With the default writable mount, changes are already in the host checkout. Review the diff from either side of the mount:
If you chose the isolated --copy-dir alternative, export a patch from the sandbox:
Copy the patch to the host:
Check that it applies cleanly before applying it:
5

Clean up

Remove the sandbox:
Removing the sandbox also removes its provider connections, sessions, and OpenCode configuration. Changes made through the default workspace mount remain in the host checkout. Never copy an agent’s entire home directory back to the host.

Use OpenCode from any project

To launch OpenCode from whichever project folder you are in, install a reusable host command:
Then run this from a project folder on your host:
--tmp creates a fresh sandbox for each session and removes it on exit. The ./ mount uses the folder you launch opencode-project from. Keep it relative; passing a full path during installation fixes the command to that folder. Project edits stay on your host. The named volumes keep OpenCode’s configuration, provider connections, and session history across runs. Other sandbox changes are discarded, so this example installs OpenCode and its dependencies again on each launch. Without --tmp, an installed command reuses the same sandbox and its original workspace mount. See msb install. To remove the host command:
The three named volumes remain until you remove them explicitly.

Reference