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\")",
},
)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_idstring optionalThe session to act in: the UUID at the end of the session's
sessionUrnandmcpUrl. For a pinned endpoint version, use the session UUID at the end of itsmcp_url, not the composite version ID. The session must belong to the authenticated user and team. Send either this header orX-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_idstring optionalThe 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 orX-Session-Id, not both. A malformed value or more than one value returns 400.x_actor_idstring optionalThe 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."codestring requiredExample:
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
Response Example
More Information
See /code/execute in the API reference for additional detail on responses, headers, parameters, and more.