When you’re building things with AI, it’s important to have a safe and separate place to do your work. The Gemini CLI has a “sandbox” feature that helps with this on your own computer. But you can make it even safer and more convenient by using it with cloud-based development environments like GitHub Codespaces and Gitpod.
Why Use the Cloud for the Gemini CLI?
Cloud development environments are like having a fresh, ready-to-use computer in the cloud that you can start using in seconds. When you use them with the Gemini CLI, you get some great benefits:
More Safety and a Separate Workspace:
- Nothing on Your Computer: Your own computer stays clean and safe. All the coding, installations, and AI work happen in the cloud. This means there’s less risk of messing up your computer or downloading something bad by accident.
- Throwaway Workspaces: You can treat each workspace like it’s disposable. If you make a mistake or want to start over, you can just delete the workspace and create a new one.
- You Control Who Gets In: Cloud environments have built-in security that lets you decide who can access your work.
Easy and Consistent Setup:
- Ready-to-Go Workspaces: With tools like Codespaces and Gitpod, you can set up your workspace with a single file. This means the Gemini CLI and all your other tools will be installed and ready to go every time you start.
- Great for Teamwork: Everyone on your team can use the exact same setup. This helps avoid the “it works on my machine” problem and makes it easier to work together.
Work from Anywhere:
- Code on Any Device: You can get to your Gemini CLI workspace from any computer with a web browser. You don’t need to set up anything on your own computer.
- Pick Up Where You Left Off: The cloud saves all your work, so you can stop and start whenever you want.
How to Set Up the Gemini CLI in the Cloud
Setting up the Gemini CLI in these cloud environments is pretty easy.
1. Set Up Your Workspace (with a .devcontainer.json
file)
In your project’s main folder, create a new folder called .devcontainer
. Inside that folder, create a file called devcontainer.json
. This file will tell the cloud environment how to set up your workspace. Here’s a simple example:
{
"name": "Gemini CLI Development",
"image": "mcr.microsoft.com/devcontainers/universal:latest",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "true",
"installOhMyZsh": "true",
"upgradePackages": "true"
}
},
"postCreateCommand": "npm install -g @google/gemini-cli",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.vscode-typescript-next",
"esbenp.prettier-vscode"
]
}
}
}
In this file:
image
: This is the basic setup for your workspace.postCreateCommand
: This is where you install the Gemini CLI. You might need to change this command depending on how you install it.customizations.vscode.extensions
: This will automatically install helpful extensions for your code editor.
2. Start Your Workspace
- GitHub Codespaces: Go to your project on GitHub, click the “Code” button, and choose “Open with Codespaces.” GitHub will then build your workspace for you.
- Gitpod: Add
gitpod.io/#
to the beginning of your GitHub project’s URL (for example,gitpod.io/#https://github.com/your-name/your-project
). Gitpod will then set up your workspace.
3. Log In and Start Coding
Once your workspace is ready, open a terminal. You’ll need to log in to the Gemini CLI, usually by giving it your API key.
gemini auth login # Or a similar command
After you log in, you can use the Gemini CLI just as you would on your own computer, but with all the benefits of the cloud.
Fixing Login Problems in the Cloud
Sometimes, you might have trouble logging in. Here are some common problems and how to fix them:
Problem: The browser login doesn’t work.
- Why: Cloud workspaces sometimes can’t open a web browser on their own.
- Solution: The Gemini CLI will usually give you a link to open in your own web browser. Copy the link, paste it into your browser, and follow the steps to log in.
Problem: Your API key isn’t working.
- Why: You might have typed the key wrong or not set it up correctly.
- Solution: Double-check that you copied the API key correctly. Make sure it’s set up as an “environment variable” in your workspace settings. You might need to restart your workspace for the changes to take effect.
Problem: You can’t connect to the internet.
- Why: Your cloud workspace might have some security settings that are blocking the connection.
- Solution: Check the error messages for any network problems. You might need to look at the documentation for Codespaces or Gitpod to see how to fix it.
Problem: You’re getting an error about
GOOGLE_CLOUD_PROJECT
.- Why: Some Gemini CLI features need to know your Google Cloud Project ID.
- Solution: Make sure you have set your Google Cloud Project ID as an “environment variable” in your workspace settings. You also need to make sure the Gemini API is turned on for your project in the Google Cloud Console.
By knowing about these common problems, you can have a much smoother time using the Gemini CLI in the cloud.
Conclusion
Using the Gemini CLI with cloud environments like GitHub Codespaces and Gitpod is a safe and powerful way to use AI in your coding. It gives you a separate, ready-to-use workspace that you can get to from anywhere. This lets you build, experiment, and work with others without worrying about messing up your own computer.
The Gemini Journals Series
- A Day with Gemini: From Code to Content
- From Lovable Dev to Gemini CLI: A Developer’s Journey
- The Gemini CLI Sandbox: A Secure Environment for AI-Powered Development
- Dynamic SEO Schemas with Gemini Journals
- My Lovable AI Experience: A Journey of Collaboration
- Our Gemini Collaboration: A Deep Dive
- Our Gemini Collaboration: Solving the Missing Cover Image
- Gemini CLI in the Cloud: Secure and Isolated Development with Codespaces/Gitpod (This Post)