Skip to content

Connect Riza to ChatGPT: Run Sandboxed Code and Manage Executions

Learn how to connect Riza to chatgpt using Truto. Step-by-step guide to tool calling, API quirks, and autonomous workflows.

Uday Gajavalli Uday Gajavalli · · 9 min read
Connect Riza to ChatGPT: Run Sandboxed Code and Manage Executions

Giving a Large Language Model (LLM) the ability to write code is a massive productivity boost. Giving it the ability to execute that code directly in your infrastructure is a critical security vulnerability. You need an isolated, ephemeral sandbox. Connecting Riza to ChatGPT allows your AI agents to safely execute code, test scripts, and orchestrate runtime environments without risking your production systems.

If your team uses Claude, check out our guide on connecting Riza to Claude or explore our broader architectural overview on connecting Riza to AI Agents.

To bridge the gap between ChatGPT and Riza's secure execution environments, you need a Model Context Protocol (MCP) server. This server translates ChatGPT's natural language tool calls into structured REST API requests that Riza understands. You can either spend weeks building, hosting, and maintaining a custom Python or Node.js MCP server, or you can use a managed integration platform like Truto to dynamically generate a secure, authenticated MCP server URL in seconds.

This guide breaks down exactly how to use Truto to generate a managed MCP server for Riza, connect it natively to ChatGPT, and execute secure sandboxed workflows using natural language.

The Engineering Reality of the Riza API

A custom MCP server is a self-hosted integration layer. While the open MCP standard provides a predictable way for models to discover tools, implementing it against specific vendor APIs is rarely straightforward. If you decide to build a custom MCP server for Riza, you own the entire API lifecycle.

Integrating Riza is not just a matter of standard CRUD operations. Riza handles dynamic code execution, which introduces unique architectural challenges that your custom MCP server must manage.

The Immutability of Runtime Revisions When you define a runtime in Riza, you cannot simply update its dependencies in place. Riza enforces strict immutability through runtime revisions. If ChatGPT decides a script needs a new Python library, it cannot just pip install it on the fly. Your MCP server must know how to invoke the create_a_riza_runtime_revision endpoint, pass the updated manifest_file and additional_python_imports, and wait for the new revision to build before executing code. If your server does not handle this relationship, the LLM will hallucinate successful package installations that never actually happen.

Parsing the Execution Payload (stdout vs stderr) When executing raw code via the Riza API, the response is not a clean, structured JSON object corresponding to your business logic. It is an execution wrapper containing exit_code, stdout, and stderr. If an LLM executes a script that prints a JSON object to stdout but also throws a warning to stderr, a naive custom MCP server might pass the entire raw response back to the model. The model must then be explicitly instructed to parse the stdout string separately from stderr to understand if the tool actually succeeded.

Handling Rate Limits and 429 Errors Executing sandboxed code is computationally expensive, and APIs like Riza enforce rate limits to protect their infrastructure. Truto does not retry, throttle, or apply backoff on rate limit errors. When the Riza API returns an HTTP 429, Truto passes that error directly to the caller. Truto normalizes the upstream rate limit information into standardized headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset) per the IETF specification. If you build a custom MCP server, you are responsible for implementing this backoff logic; otherwise, the LLM will assume the code execution succeeded when it actually dropped.

Generating the Managed MCP Server

Instead of building and hosting a custom integration layer to handle Riza's execution logic, you can use Truto to generate a managed MCP server. Truto dynamically builds tool definitions directly from the integration's documentation and schema, ensuring ChatGPT always has access to the latest endpoints.

You can create this server via the Truto UI or programmatically via the API.

Method 1: Via the Truto UI

For administrators who want a quick, visual setup:

  1. Log into your Truto dashboard and navigate to the Integrated Accounts page.
  2. Select your connected Riza account.
  3. Click on the MCP Servers tab.
  4. Click Create MCP Server.
  5. Select your desired configuration (e.g., filtering for specific methods or tags) and set an optional expiration date.
  6. Copy the generated MCP server URL (it will look like https://api.truto.one/mcp/a1b2c3d4...).

Method 2: Via the Truto API

For engineering teams orchestrating agent infrastructure programmatically, you can generate the MCP server via a single API call. This provisions the server on distributed edge storage and returns a ready-to-use URL.

curl -X POST https://api.truto.one/integrated-account/{integrated_account_id}/mcp \
  -H "Authorization: Bearer YOUR_TRUTO_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Riza Sandbox Executions",
    "config": {
      "methods": ["create", "get", "list"]
    }
  }'

The response contains the secure URL you will feed to ChatGPT:

{
  "id": "mcp_8f7e6d5c",
  "name": "Riza Sandbox Executions",
  "config": { "methods": ["create", "get", "list"] },
  "expires_at": null,
  "url": "https://api.truto.one/mcp/a1b2c3d4e5f67890"
}

Connecting the MCP Server to ChatGPT

Once you have your Truto MCP server URL, you must register it with ChatGPT. You can do this through the ChatGPT application interface or via a local configuration file for programmatic agent setups.

Method A: Via the ChatGPT UI

If you are using the ChatGPT Desktop application or web interface with developer mode enabled:

  1. Open ChatGPT and navigate to Settings.
  2. Go to Apps -> Advanced settings (or Connectors depending on your plan tier).
  3. Enable Developer mode.
  4. Under MCP servers / Custom connectors, click Add.
  5. Name the connector (e.g., "Riza Code Sandbox").
  6. Paste your Truto MCP Server URL.
  7. Click Save.

ChatGPT will immediately connect to the URL, execute a handshake, and ingest the list of available Riza execution tools.

Method B: Via Manual Configuration File

If you are running a local agent testing environment or using the Claude Desktop app as a testing harness for your MCP architecture, you can register the server via a standard JSON configuration file. You will use the standard SSE transport proxy to route requests to Truto's edge network.

Add the following to your MCP configuration file (e.g., mcp_config.json or claude_desktop_config.json):

{
  "mcpServers": {
    "riza-sandbox": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-sse",
        "https://api.truto.one/mcp/a1b2c3d4e5f67890"
      ]
    }
  }
}

Hero Tools for Riza

Once connected, Truto exposes Riza's API endpoints as structured tools. Here are the most critical operations your AI agent will use to orchestrate code execution and manage sandbox environments.

create_a_riza_code_execution

This is the core tool for running ad-hoc scripts. It accepts a programming language and a raw code string, executes it in an isolated Riza sandbox, and returns the standard output, standard error, exit code, and execution duration.

"Write a Python script to calculate the first 50 Fibonacci numbers, and execute it in Riza using the create_a_riza_code_execution tool. Tell me exactly how long the execution took based on the duration metric."

create_a_riza_function_execution

Unlike raw code execution, function execution requires the submitted code to define an execute function that accepts a single argument and returns a JSON-serializable value. This is highly effective when ChatGPT needs to process a specific input payload through a custom algorithm and requires structured data back instead of raw strings.

"I have a complex JSON payload of user behavior data. Execute a function in Riza that parses this payload, filters out users with a session time under 30 seconds, and returns the clean JSON object. Use create_a_riza_function_execution."

create_a_riza_runtime

Before executing complex code with external dependencies, you must define the environment. This tool creates a new runtime specification in Riza, establishing the base language and the manifest file (like a requirements.txt or package.json) required for execution.

"Create a new Riza runtime named 'data-science-env' for Python. The manifest file should specify that we need pandas and numpy installed."

create_a_riza_tool

If ChatGPT writes a script that you want to reuse as a permanent tool in your Riza project, you can use this operation. It registers the code, assigns it an input schema, and binds it to a specific runtime revision. This turns transient AI-generated code into a durable, versioned asset.

"Take the data validation script we just wrote and register it as a permanent Riza tool using create_a_riza_tool. Set the input schema to expect a 'user_id' string and an 'email' string."

create_a_riza_tool_execution

Once a permanent tool is registered, ChatGPT can invoke it by ID and pass an input payload that matches the tool's defined schema. The response is the JSON-serializable value produced by the tool's execute function.

"Run the data validation tool we registered earlier. The tool ID is 'tool_01xyz'. Pass my email and user ID into the execution payload and give me the result."

list_all_riza_executions

This tool allows the LLM to audit historical sandbox activity. It lists all executions in your Riza project, returning details like language, exit code, duration, and started time. It is essential for debugging failed agent tasks.

"List all recent Riza executions. Filter for only failed executions using the only_non_zero_exit_codes parameter, and summarize the stderr output from the last 3 failures."

For the complete tool inventory and detailed JSON schemas, view the Riza integration page.

Workflows in Action

To understand the value of an MCP-connected LLM, look at how an AI agent coordinates multiple Riza endpoints to solve complex engineering and operational problems.

Scenario 1: Securing AI-Generated Data Processing

Persona: Data Engineer or Backend Developer
Goal: Generate a complex Python data transformation script and validate it safely before deploying it to production.

"I need a Python script that ingests a CSV string of financial transactions, identifies duplicate transaction IDs, and returns a clean JSON array. Write the script, execute it in a Riza sandbox to verify it works, and if the exit code is 0, register it as a permanent Riza tool."

Step-by-Step Execution:

  1. create_a_riza_code_execution: ChatGPT writes the Python logic and immediately submits it to Riza as an ad-hoc code execution, passing a dummy CSV string inline.
  2. Evaluate Response: ChatGPT reads the stdout and exit_code. If the code fails (e.g., a syntax error caught in stderr), ChatGPT modifies the script and retries.
  3. create_a_riza_tool: Once the ad-hoc execution succeeds, ChatGPT registers the finalized code as a permanent tool, defining the input schema to accept a CSV string.

Result: The developer gets a fully tested, deployed sandbox tool without ever running untrusted code on their local machine or production servers.

sequenceDiagram
    participant ChatGPT as ChatGPT
    participant Truto as Truto MCP Server
    participant Riza as Riza API
    ChatGPT->>Truto: Call create_a_riza_code_execution
    Truto->>Riza: Proxy execution request
    Riza-->>Truto: Return exit_code and stdout
    Truto-->>ChatGPT: Format as JSON-RPC response
    ChatGPT->>Truto: Call create_a_riza_tool
    Truto->>Riza: Register permanent tool
    Riza-->>Truto: Return tool_id
    Truto-->>ChatGPT: Return success

Scenario 2: Auditing and Debugging Sandbox Failures

Persona: DevOps Admin or IT Support
Goal: Investigate a sudden spike in failed code executions within the company's Riza environment.

"We are seeing job failures in our sandboxes. List all recent failed Riza executions. Find the runtime ID associated with the most common failure, and then list the runtime revisions for that environment so we can see if a dependency changed."

Step-by-Step Execution:

  1. list_all_riza_executions: ChatGPT queries the execution logs, setting only_non_zero_exit_codes to true.
  2. Analyze Errors: ChatGPT parses the stderr strings from the response and identifies that the most common error is a missing Python package in a specific runtime.
  3. get_single_riza_runtime_revision_by_id: ChatGPT fetches the exact runtime revision to inspect the manifest_file and additional_python_imports.

Result: The admin receives an immediate root-cause analysis showing exactly which package dependency is missing from the runtime manifest, complete with the specific error trace from the Riza logs.

Security and Access Control

When exposing dynamic code execution infrastructure to an AI model, strict guardrails are mandatory. Truto’s managed MCP servers provide zero-trust configuration layers applied before the API requests ever reach Riza.

  • Method Filtering: Restrict the MCP server to read-only operations using methods: ["read"]. This allows ChatGPT to audit executions and list runtimes without the ability to execute new code or alter manifests.
  • Tag Filtering: Limit the server's scope to specific API domains. If Riza defines tags for executions and runtimes, you can scope a server to only manage runtimes while blocking execution commands entirely.
  • API Token Auth: By setting require_api_token_auth: true, possession of the MCP URL is no longer sufficient. The ChatGPT client must also pass a valid Truto API token in the Authorization header to execute tool calls.
  • Automatic Expiration: Use expires_at to grant temporary sandbox access to contractors, AI agents, or specific testing workflows. Once the timestamp passes, the server invalidates its credentials at the edge network and deletes itself.

Empowering Agents with Safe Sandboxes

Connecting Riza to ChatGPT via Truto's MCP Server changes how you build AI infrastructure. Instead of worrying about LLM hallucinations bricking your production database or executing malicious code on your local machine, you constrain the model's output to a secure, ephemeral sandbox.

By leveraging a managed infrastructure layer, you eliminate the overhead of hosting custom Python servers, maintaining upstream schemas, and building manual proxy tunnels. Your agents get dynamic tools. Your engineering team gets their time back.

More from our Blog