docs/examples/agents/gemini-cli.mdx
This example runs the official scoped Gemini CLI package inside a disposable Node.js microVM. The project is mounted from your host, while Gemini authentication and settings live on the sandbox's root disk.
<Tooltip tip="Writable host-directory mounts are local-only. On microsandbox cloud, use the isolated-copy alternative and omit replace-on-create."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>
<CodeGroup> ```sh macOS & Linux msb run -t --name gemini-demo --replace \ --cpus 2 --memory 2G --root-disk 4G \ --mount-dir ./my-project:/workspace:rw \ --workdir /workspace \ node:24-bookworm-slim -- sh -lc ' apt-get update && apt-get install -y --no-install-recommends ca-certificates git && npm install -g @google/[email protected] && exec gemini ' ```msb run -t --name gemini-demo --replace `
--cpus 2 --memory 2G --root-disk 4G `
--mount-dir ./my-project:/workspace:rw `
--workdir /workspace `
node:24-bookworm-slim -- sh -lc '
apt-get update &&
apt-get install -y --no-install-recommends ca-certificates git &&
npm install -g @google/[email protected] &&
exec gemini
'
Gemini CLI first asks whether you trust the workspace. Review the mounted project, then continue to authentication.
<Tip> For an isolated workspace, or when using microsandbox cloud, replace `--mount-dir ./my-project:/workspace:rw` with `--copy-dir ./my-project:/workspace`. </Tip> <Warning> Install the scoped package exactly as shown: `@google/gemini-cli`. Do not substitute similarly named unscoped packages. </Warning> </Step> <Step title="Start another session">After leaving Gemini CLI, return to the same sandbox and workspace with:
msb exec -t gemini-demo -- gemini
Exit the TUI and run:
msb exec gemini-demo -- gemini --version
The pinned example prints 0.52.0.
With the default writable mount, changes are already in the host checkout. Review them inside the sandbox:
msb exec gemini-demo -- sh -lc 'cd /workspace && git status --short && git diff --stat && git diff'
If you chose the isolated --copy-dir alternative, create a patch inside the sandbox:
msb exec gemini-demo -- sh -lc 'cd /workspace && git add -N . && git diff --binary > /tmp/gemini.patch'
Copy the patch to the host:
msb cp gemini-demo:/tmp/gemini.patch ./gemini.patch
Check that it applies cleanly before applying it:
git apply --check ./gemini.patch
Remove the sandbox:
msb rm -f gemini-demo
Removing the sandbox also removes its Gemini authentication and settings. Changes made through the default workspace mount remain in the host checkout.
</Step> </Steps>