What You’ll Learn
- Sending prompts to the Google Gemini API (
gemini-2.0-flash) using thegoogle-genaiSDK - Using
client.models.generate_content()— the newer Google AI SDK interface - Stripping markdown code fences from LLM responses before execution
- Writing generated code into a Declaw sandbox filesystem
- Executing the code securely with
sbx.commands.run() - Graceful demo mode when no API key is configured
Prerequisites
- Declaw instance running and
DECLAW_API_KEY/DECLAW_DOMAINset GOOGLE_API_KEY(optional — the example runs in demo mode without it)
Code Walkthrough
This example is available in Python. TypeScript support coming soon.
1. Ask Gemini to generate Python code
Thegoogle-genai SDK (the newer Google AI SDK, distinct from the older google-generativeai) uses a Client with models.generate_content():
Use
google-genai (not google-generativeai). The newer SDK ships as from google import genai and uses the genai.Client() pattern shown above.