pydo.gateway_code.run()

Generated on 6 Nov 2026 from pydo version v0.45.0

Usage

client.gateway_code.run(
    x_session_id=None,
    x_endpoint_id=None,
    x_actor_id=None,
    body={
        "code": "print(\"hello from Action Gateway\")",
    },
)
Returns JSON Raises HttpResponseError

Description

Runs Python code in an ephemeral sandbox and returns its stdout, stderr, and exit_code. This is the REST form of the action_code MCP tool. Use it for computation, parsing, and data processing, or to chain several catalog tools in one request.

The sandbox provides invoke_digitalocean_tool(name, arguments), which calls a catalog tool and returns a tool result. Those calls follow the session’s tool selection and policy. Each request runs in a fresh sandbox, so state is not kept between requests. Execution, including tool calls, is time limited. Code that runs too long fails with a timeout error.

A nonzero exit code is still a succeeded result; check output.exit_code. If the session policy requires approval for action_code, the response is a failed result with _meta.status set to requires_approval.

Parameters

x_session_id string optional

The session to act in: the UUID at the end of the session's sessionUrn and mcpUrl. For a pinned endpoint version, use the session UUID at the end of its mcp_url, not the composite version ID. The session must belong to the authenticated user and team. Send either this header or X-Endpoint-Id, not both; both returns 400. With neither, the request uses your default endpoint when default endpoints are enabled for your team, and otherwise returns 403.

x_endpoint_id string optional

The endpoint to act in, as a lowercase endpoint UUID. The request uses the endpoint's current head version, which the response reports in X-Action-Gateway-Endpoint-Version. The endpoint must belong to the authenticated user and team; an unknown or inaccessible endpoint returns 404. Send either this header or X-Session-Id, not both. A malformed value or more than one value returns 400.

x_actor_id string optional

The actor you expect the session or endpoint to be bound to. It does not select an actor or connections; those come from the session's or endpoint's actor_id. When sent, it must equal that binding. A different value, including any value for a target with no actor, returns 403 with the message "The session is not bound to the request's actor."

code string required

Example: print("hello from Action Gateway")

Python source to run. The sandbox provides invoke_digitalocean_tool(name: str, arguments: dict) -> dict, which calls a catalog tool under the session's policy and returns a tool result.

Request Sample

Show Request Sample
import os
from pydo import Client

client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))

req = {
  "code": "print(\"hello from Action Gateway\")"
}

resp = client.gateway_code.run(body=req)

Response Example

Show Response Example
{
  "status": "succeeded",
  "output": {
    "stdout": "hello from Action Gateway\n",
    "exit_code": 0
  },
  "call_id": "call_8b7c6d5e-4f3a-4b2c-9d1e-0f9a8b7c6d5e"
}

More Information

See /code/execute in the API reference for additional detail on responses, headers, parameters, and more.

We can't find any results for your search.

Try using different keywords or simplifying your search terms.