Skip to main content

What You’ll Learn

  • Sending prompts to Groq’s OpenAI-compatible API (llama-3.1-8b-instant) for ultra-fast code generation
  • 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
  • GROQ_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 Groq to generate Python code

The Groq SDK follows the OpenAI client interface exactly — swap in Groq() and choose a model:
Groq’s hosted inference is significantly faster than most cloud LLM providers. llama-3.1-8b-instant typically responds in under 200 ms, making it a good choice for high-throughput code-generation pipelines.

2. Strip code fences and execute in a sandbox

3. Demo mode (no API key needed)

Expected Output