docs/examples/agents/gemini-cli.mdx
This example runs the official scoped Gemini CLI package inside a disposable Node.js microVM. The project is copied into the guest, while Gemini authentication and settings live in a named volume.
<Tooltip tip="On microsandbox cloud, create the named volume first and omit replace-on-create from this command."><span className="msb-badge-limited">Limited on cloud <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 \ --copy-dir ./my-project:/workspace \ --workdir /workspace \ --mount-named gemini-data:/root/.gemini \ 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 `
--copy-dir ./my-project:/workspace `
--workdir /workspace `
--mount-named gemini-data:/root/.gemini `
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 copied files, then continue to authentication. The sandbox cannot directly modify the original host directory.
<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.
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
Remove persisted Gemini data only when you no longer need it:
msb volume rm gemini-data