Short answer: Gemini CLI has a --sandbox flag for local isolation, but if you want its shell commands on a different machine entirely, run Gemini CLI on a cloud computer and call it with -p. A Sandscale workspace is a Firecracker microVM with its own kernel and a persistent disk, and Sandscale's workspace docs name Gemini CLI as one of the agents you can run inside one.
Sources, read in November 2026: Gemini CLI's headless mode reference and CLI reference, and Sandscale's workspaces concept page and workspaces guide.
1. Create a workspace
sandscale login
sandscale workspace templates list
sandscale workspace create gemini-box --template TEMPLATE
sandscale workspace open gemini-box
TEMPLATE is a name templates list prints. Gemini CLI needs to reach Google's API. Network access follows your plan and your organization's policy, so check that yours lets the workspace reach it.
Inside the workspace, install Gemini CLI with npm, authenticate it the way its docs describe, and clone your repository:
npm install -g @google/gemini-cli
2. Run it headless
Per the headless reference, Gemini CLI runs non-interactively when it is not attached to a terminal or when you pass -p (or --prompt):
cd ~/src/my-service
gemini -p "List the modules without tests and suggest one test for each" --output-format json > out.json
With --output-format json the result is one JSON object with response (the final answer), stats (token use and latency) and, on failure, error. --output-format stream-json gives newline-delimited events instead: init, message, tool_use, tool_result, error and result.
3. Pick an approval mode on purpose
--approval-mode sets how tool calls are approved. Per the CLI reference the choices are default, auto_edit, yolo and plan; the older --yolo flag is deprecated in favour of --approval-mode=yolo.
On your laptop, yolo means the model's shell commands run on your machine without asking. On a workspace they run in the workspace's microVM, against its disk, which is a more reasonable place for an unattended run. A reasonable default for scripted runs is auto_edit for file edits only, and yolo only on a workspace you are prepared to throw away or restore from git.
4. Branch on the exit code
The headless reference lists exit codes: 0 success, 1 general error or API failure, 42 input error (invalid prompt or arguments) and 53 turn limit exceeded. From your laptop:
sandscale workspace ssh gemini-box -- 'cd ~/src/my-service && gemini -p "fix the type errors" --approval-mode auto_edit'
echo "gemini exited with $?"
sandscale workspace ssh runs the words after -- on the workspace with a short-lived certificate and a checked host key. Like ssh, it joins those words with spaces, so quote the remote command.
5. Stop it
sandscale workspace schedule idle gemini-box 30m
sandscale workspace stop gemini-box
Stopping keeps the disk, and the workspace uses your plan's vCPU-hours only while it runs. Your organization's policy can shorten a schedule you set.
Local --sandbox or a workspace?
Gemini CLI's --sandbox flag runs it "in a sandboxed environment for safer execution" on the machine you start it on. A workspace moves the whole agent to a separate microVM with its own kernel. They are not exclusive: you can still use Gemini CLI's own options inside the workspace. For a broader look at isolation layers, see containers, gVisor and Firecracker for agent code.
FAQ
How do I run Gemini CLI non-interactively?
Pass -p (or --prompt) with your prompt. Add --output-format json for a single JSON object with the response and stats, or --output-format stream-json for an event stream.
What does exit code 53 mean in Gemini CLI?
Per Gemini CLI's headless reference, 53 means the turn limit was exceeded. 42 is an input error, 1 a general error or API failure, and 0 success.
Is the yolo flag still supported?
The CLI reference marks --yolo as deprecated and says to use --approval-mode=yolo instead.
Can Gemini CLI run in a Sandscale workspace?
Yes. Sandscale's workspace docs list Gemini CLI among the agents you can run inside a workspace. The workspace needs network access to reach Google's API.
Related
- Running Claude Code headless in a cloud workspace
- Running Codex with codex exec in a cloud workspace
- Use case: a coding agent that keeps working after you close the laptop
Originally published on the Sandscale blog.
Top comments (0)