Skip to main content

What You’ll Learn

  • Sending prompts to the Google Gemini API (gemini-2.0-flash) using the google-genai SDK
  • 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_DOMAIN set
  • 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

The google-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.

2. Strip code fences and execute in a sandbox

3. Demo mode (no API key needed)

Expected Output