Skip to main content

What You’ll Learn

  • Implementing a Haystack @component with component.output_types that runs Python in a Declaw sandbox
  • Connecting the component in a Haystack Pipeline alongside OpenAIGenerator and PromptBuilder
  • Demo mode that exercises the component 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 DecawCodeRunner component

Use the @component decorator and declare output types with @component.output_types. The run() method receives typed inputs and returns a dict matching the declared output types:
The output and exit_code output names can be connected to downstream components in the pipeline by referencing code_runner.output and code_runner.exit_code.

2. Build a pipeline with an LLM and the code runner

3. Run the pipeline

4. Demo mode (no API key needed)

Run the component directly without building a pipeline:

Expected Output

In demo mode: