Creating custom tools
Write JavaScript, TypeScript, or Python code that Agents can execute during a run. Use custom tools for validation, transforms, and business logic that don’t need an external API.
Create a custom tool
- Click Tools in the sidebar
- Click Create Tool
- Select Custom Code
- Configure the tool:
- Name: Unique identifier (e.g.,
calculate_discount) - Description: What the tool does and when to use it
- Sandbox: Execution environment — see below
- Parameters: Define the input schema
- Code: Your implementation
- Name: Unique identifier (e.g.,
- Click Create
Pick a sandbox
Runtype runs your code in an isolated environment. Choose the one that matches your needs:
Cloudflare Worker runs in-process inside Runtype’s edge workers. It is the fastest option and requires no setup.
Daytona is useful when you need Python, TypeScript, or a containerized environment with configurable outbound access. To use Daytona, add your API key in Settings → Integrations. If Daytona is not configured, tool execution fails and the Agent receives a null result.
QuickJS is still available for backwards compatibility but is not recommended for new tools.
Writing tool code
Your code receives input via an injected parameters object. The shape is determined by the parameter schema you define.
JavaScript (Cloudflare Worker / QuickJS)
Python (Daytona)
In Python, write the result to stdout as JSON. Runtype captures the output and parses it.
Runtime behavior
Return values. In JavaScript, the returned object is passed directly to the Agent. In Python, the last line of stdout must be valid JSON.
Exceptions. Unhandled exceptions fail the tool and return an error to the Agent. Use structured error returns (see below) if you want the Agent to recover.
Secrets and network. Cloudflare Worker tools have no network access and cannot read managed secrets. Daytona tools inherit network and secret policy from your container configuration.
Available features
Cloudflare Worker / QuickJS:
- Standard JS built-ins (
Array,Object,Math,Date,JSON) async/await, arrow functions, destructuring, template literals- Regex and string manipulation
- Helper utilities via the
helpersnamespace (see below) console.logoutput is captured in tool execution logs
Helper functions are accessed through the helpers namespace:
Daytona:
- Standard library modules available in your Daytona container image
pippackages (Python) ornpmpackages (JS/TS) — availability depends on your Daytona configurationfetchand outbound network calls — allowed or blocked based on your Daytona sandbox policy
Defining parameters
Click + Add Parameter and configure each field:
Example:
Execution limits
Set timeout and memory per tool:
- Timeout: 1,000 ms to 300,000 ms. Default is 30,000 ms (30 s).
- Memory: 8 MB, 16 MB, or 32 MB. Default is 16 MB.If your code exceeds memory, the tool fails and returns an error. Cloudflare Workers return a timeout error to the Agent when the limit is exceeded. Daytona behavior depends on your container policy—typically a hard kill.
Code validation
Runtype runs a static AST check before saving any custom tool.
Errors (block save):
eval()— error codeUSE_OF_EVALnew Function()— error codeUSE_OF_FUNCTION_CTOR- Syntax errors
Warnings (surfaced in the dashboard, do not block save):
- Unbounded
while (true)loops without abreakorawait— warning codeINFINITE_LOOP - Dynamic
import()expressions — warning codeDYNAMIC_IMPORT - Missing
returnstatement in JavaScript/TypeScript (Cloudflare Worker and QuickJS only) — warning codeRETURN_UNDEFINED
The check runs again on every update.
Error handling
Return structured errors so the Agent can recover:
Testing tools
Use the Test panel on the tool page:
- Enter sample values for your parameters
- Click Run Test
- Review the output, execution time, and console logs
- Iterate until correctTest output includes the returned value and any
console.logcalls.
Best practices
- Single responsibility. Each tool should do one thing well.
- Validate inputs. Check parameter values before processing.
- Clear naming.
calculate_shipping_costis better thanprocess. - Return structured data. Objects are easier for Agents to work with than raw strings.
- Handle errors gracefully. Return
{ success: false, error: "..." }instead of throwing. - One operation per tool. Agents struggle to debug multi-step logic inside a single tool call.
- Write explicit descriptions. Agents use the tool and parameter descriptions to decide when to invoke the tool and what values to pass.
Examples
Email validator
Parameters: email (string, required)
Date formatter
Parameters: isoDate (string, required), format (string, default: "iso")
Array aggregator (Python)
Parameters: numbers (array of numbers, required)
Next steps
- Creating external tools — for HTTP API integrations
- Agent tools — how Agents select and invoke tools
- Built-in tools — ready-to-use integrations (Exa, Firecrawl, GPT Image 2)
- What are Tools? — conceptual background