Skip to main content
Code Mode gives your navigator a sandboxed Python runtime for tool-heavy workflows.

What it does

When enabled, the Navigator exposes execute_tools_in_code alongside its standard discovery and execution tools. The agent can use it to coordinate tool calls, process large or paginated responses, and perform calculations before returning an answer. Intermediate tool outputs stay inside the sandbox, so only the program’s printed result enters the model’s context.

How to enable

1

Open the Navigator Instance

In the Caylex dashboard, open a project, select its navigator, and go to Caylex Capabilities.
2

Enable Code Mode

Turn on Code Mode for the Navigator Instance.

How it works

When the agent decides to use Code Mode, the following steps occur:
  1. Program generation — the agent generates a fresh Python program and passes it to execute_tools_in_code.
  2. Sandbox execution — the Navigator runs the program in a restricted sandbox with access to the async invoke_tools function.
    • Whenever invoke_tools is called, the Navigator executes the requested connected tools and returns their responses to the program.
  3. Result delivery — the Navigator returns only the program’s printed output to the model.
Tool calls still use the same Navigator execution path as regular calls. Authentication, permissions, approval requirements, analytics, and error handling continue to apply.

The execute_tools_in_code interface

Your agent calls execute_tools_in_code with a generated Python program:
The request includes:
  • code — the Python source to run in the restricted sandbox
The response contains an output string with everything the program printed to standard output. Inside the program, the agent can use invoke_tools to call connected tools.

The invoke_tools function

Code Mode exposes an async invoke_tools function inside the sandbox. The generated program calls it with a list of tool calls:
Each tool call includes:
  • server_name — the connected server to use
  • tool_name — the tool to invoke
  • intent — a short description of why the tool is being called
  • tool_params — the parameters defined by the tool’s input schema
The function returns an ordered list[str] containing each tool’s raw response. JSON responses remain encoded as strings and can be parsed with json.loads.

Processing large results

Code Mode can transform tool responses before they enter the model’s context. Suppose a user asks for the total value of every invoice from a paginated billing endpoint. The generated program could retrieve each page and return only the final sum:
The model receives one small result instead of every invoice. The same approach can filter, sort, group, deduplicate, join, or otherwise process tool responses inside the sandbox.

Important notes

  • Tool output discovery — Before writing code, the agent should check each tool’s output schema. If the shape is still unclear, it should make a representative tool call and inspect the response first.
  • Failure handling — Code Mode stops the program when a tool call fails. The error identifies the failed line, the tool calls in submission order, and the error message for each failed tool, so the agent can avoid repeating successful state-changing tool calls.
  • Restricted Python environment — Code runs in Monty, a restricted Python interpreter that supports common Python syntax and a limited standard library. It cannot directly access the network, filesystem, environment variables, subprocesses, or third-party packages.

When to use Code Mode