Skip to main content

What You’ll Learn

  • Defining a @tool with langchain_core.tools that executes Python in a Declaw sandbox
  • Creating a LangGraph ReAct agent with create_react_agent
  • Demo mode that exercises the sandbox tool 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)
This example is available in Python. TypeScript support coming soon.

Code Walkthrough

1. Define the Declaw sandbox tool

Wrap Sandbox.create() in a LangChain @tool. The agent receives the function’s docstring as the tool description, so make it clear:
Each call to execute_python spins up a fresh sandbox, runs the code, and destroys the sandbox. Sandboxes are fully isolated — code from one call cannot affect another.

2. Create a LangGraph ReAct agent

3. Run the agent

The agent will reason about the task, call execute_python with the generated code, receive the sandbox output, and formulate a final answer.

4. Demo mode (no API key needed)

Run the sandbox tool directly without the LangGraph agent:

Expected Output

In demo mode: