Run typed Python logic in an isolated tool environment.
Create a Custom Code tool for calculations and data processing that do not need
network access. The Python input and output models become the tool contract the
agent sees.
A deterministic Python task that can run without an internet connection.
Vault secrets for any sensitive values the code needs.
1
Create the draft
Dashboard
API
Go to Global Tools, choose New tool, then select Custom Code.
Enter a precise tool name and Instructions. Instructions maps to
the API description field.
Define a Pydantic Input model, an Output model, and a synchronous
handler(input: Input) -> Output function. Add field descriptions so the
model knows which values to supply.Return the declared output model. Keep logs useful for testing, but return
the data the agent needs from the handler.
3
Add dependencies and secrets
List each dependency as an exact version such as pydantic==2.11.7.
Packages with URLs, environment markers, or extras are rejected.Declare Vault secret names separately from the source. Do not place secret
values in code or logs. The environment exposes only the declared secrets.
Dashboard
API
Expand Metadata, select the Vault secrets the tool can access, and
enter the pinned packages in Dependencies.
Configure Vault secrets and Python dependencies
Add the allowed Vault secret names to declared_secrets and the pinned
packages to dependencies in the tool request.
4
Build the tool
Dashboard
API
Save the draft, then choose Build tool.
Build the tool after defining its code and metadata
Save the draft, then send
POST /v1/agents/tools/{tool_id}/introspect.
The build installs the pinned dependencies, imports the declared modules,
and derives the argument schema from the Pydantic models.
5
Test and publish
Run representative input, check the structured output and logs, then
publish. You must have a valid schema, available secrets and dependencies,
and a successful run for the current draft.
Custom Code runs in an isolated environment with no internet access. Use an
API Request tool or
MCP server for network calls.
Avoid unbounded loops, large payloads, and large output objects. A run that
exceeds its time or data limit returns a failure instead of partial output.Code tools can run on call start, first user message, and tool success or
failure. They cannot run on call end. See
Run a tool on call events.
Assistant
Responses are generated using AI and may contain mistakes.