Back to Microsandbox

Gemini CLI

docs/examples/agents/gemini-cli.mdx

0.6.102.6 KB
Original Source

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.

Run Gemini CLI

<Steps> <Step title="Start Gemini CLI">

<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 ' ```
powershell
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
  '
</CodeGroup>

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:

sh
msb exec -t gemini-demo -- gemini
</Step> <Step title="Verify the installation">

Exit the TUI and run:

sh
msb exec gemini-demo -- gemini --version

The pinned example prints 0.52.0.

</Step> <Step title="Export changes">

Create a patch inside the sandbox:

sh
msb exec gemini-demo -- sh -lc 'cd /workspace && git add -N . && git diff --binary > /tmp/gemini.patch'

Copy the patch to the host:

sh
msb cp gemini-demo:/tmp/gemini.patch ./gemini.patch

Check that it applies cleanly before applying it:

sh
git apply --check ./gemini.patch
</Step> <Step title="Clean up">

Remove the sandbox:

sh
msb rm -f gemini-demo

Remove persisted Gemini data only when you no longer need it:

sh
msb volume rm gemini-data
</Step> </Steps>

Reference