> ## Documentation Index
> Fetch the complete documentation index at: https://docs.declaw.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agno (Phidata) + Declaw

> Build an Agno (formerly Phidata) Toolkit that wraps Declaw sandbox execution, then attach it to an Agno Agent for secure, sandboxed Python code execution.

## What You'll Learn

* Building an Agno `Toolkit` subclass that executes Python in a Declaw sandbox
* Registering toolkit methods with `self.register()`
* Creating an Agno `Agent` with the toolkit and an OpenAI model
* Demo mode that exercises the sandbox toolkit directly 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)

```bash theme={null}
pip install declaw python-dotenv agno
```

<Note>This example is available in Python. TypeScript support coming soon.</Note>

## Code Walkthrough

### 1. Define a `DecawTools` Toolkit

Subclass `Toolkit` and register each tool method. The docstring becomes the tool description that the LLM sees:

```python theme={null}
from agno.tools import Toolkit
from declaw import Sandbox

class DecawTools(Toolkit):
    def __init__(self) -> None:
        super().__init__(name="declaw")
        self.register(self.execute_python)

    def execute_python(self, code: str) -> str:
        """Execute Python code in a secure Declaw sandbox."""
        sbx = Sandbox.create(template="python", timeout=300)
        try:
            sbx.files.write("/tmp/code.py", code)
            result = sbx.commands.run("python3 /tmp/code.py", timeout=30)
            return f"{result.stdout}\n{result.stderr}".strip()
        finally:
            sbx.kill()
```

### 2. Create an Agno Agent with the toolkit

```python theme={null}
from agno.agent import Agent
from agno.models.openai import OpenAIChat

toolkit = DecawTools()

agent = Agent(
    model=OpenAIChat(id="gpt-4o-mini"),
    tools=[toolkit],
    instructions=[
        "You are a helpful assistant that can execute Python code in a secure sandbox.",
        "Use the execute_python tool to run code.",
    ],
    show_tool_calls=True,
    markdown=True,
)
```

### 3. Run the agent

```python theme={null}
prompt = "Write Python code to generate a multiplication table for 7 (1 through 12) and print it."
agent.print_response(prompt)
```

### 4. Demo mode (no API key needed)

```python theme={null}
from declaw import Sandbox

code = """\
print("Multiplication table for 7:")
for i in range(1, 13):
    print(f"  7 x {i:2d} = {7 * i:3d}")
"""

sbx = Sandbox.create(template="python", timeout=300)
try:
    sbx.files.write("/tmp/code.py", code)
    result = sbx.commands.run("python3 /tmp/code.py", timeout=30)
    print(result.stdout)
finally:
    sbx.kill()
```

## Expected Output

In demo mode:

```
=======================================================
Agno (Phidata) + Declaw Sandbox Example
=======================================================
No OPENAI_API_KEY found -- running demo mode.

--- Toolkit Definition ---
class DecawTools(Toolkit):
    def __init__(self):
        super().__init__(name="declaw")
        self.register(self.execute_python)
    ...

--- Running Code Directly in Declaw Sandbox ---
Code:
print("Multiplication table for 7:")
for i in range(1, 13):
    print(f"  7 x {i:2d} = {7 * i:3d}")

stdout: Multiplication table for 7:
  7 x  1 =   7
  7 x  2 =  14
  7 x  3 =  21
  7 x  4 =  28
  7 x  5 =  35
  7 x  6 =  42
  7 x  7 =  49
  7 x  8 =  56
  7 x  9 =  63
  7 x 10 =  70
  7 x 11 =  77
  7 x 12 =  84

Sandbox cleaned up.

=======================================================
Done!
=======================================================
```
