Skip to main content

What You’ll Learn

  • Implementing the CodeExecutor ABC from autogen_core.code_executor backed by Declaw sandboxes
  • Supporting both Python and shell code blocks
  • Integrating with CodeExecutorAgent and AssistantAgent
  • Running a RoundRobinGroupChat team with termination conditions
  • Demo mode that exercises the executor without needing an OpenAI key

Prerequisites

  • Declaw instance running and DECLAW_API_KEY / DECLAW_DOMAIN set
  • OPENAI_API_KEY (optional — the example runs in demo mode without it)
This example is available in Python. TypeScript support coming soon.

Code Walkthrough

1. Implement DecawCodeExecutor

Subclass CodeExecutor and implement execute_code_blocks. The method receives a list of CodeBlock objects — each has a language and code field:
A fresh sandbox is created per execute_code_blocks call, ensuring full isolation between turns.

2. Wire into AutoGen agents

3. Run the team

4. Demo mode (no API key needed)

Run the executor directly without an AutoGen agent:

Expected Output

In demo mode: