---
title: Code Execution Tool (public)
description: Action Gateway runs an agent&#39;s Python code in an ephemeral sandbox, with optional programmatic tool calling for advanced workflows.
product: Managed Agents
url: https://docs.digitalocean.com/products/managed-agents/action-gateway/concepts/code-execution-tool/
last_updated: "2026-09-21"
---

> **For AI agents:** The documentation index is at [https://docs.digitalocean.com/llms.txt](https://docs.digitalocean.com/llms.txt). Markdown versions of pages use the same URL with `index.html.md` in place of the HTML page (for example, append `index.html.md` to the directory path instead of opening the HTML document).

# Code Execution Tool (public)

Action Gateway gives applications and AI agents governed access to tens of thousands of tools through a managed MCP endpoint or SDK. See [What You Can Build](https://docs.digitalocean.com/products/managed-agents/agent-harness-runtime/details/what-you-can-build/index.html.md) for example use cases of Action Gateway with Harness Runtime.

Action Gateway’s `action_code` meta tool gives your agent an ephemeral sandbox to run Python. Use it for calculations, parsing, or data processing without searching for or calling another tool.

## Sandbox Execution

The agent supplies Python source in the `code` argument. The response contains standard output, standard error, and the exit code. Print the results the agent needs; variables are not automatically returned.

Each call starts a fresh sandbox. Files, variables, and installed packages do not persist between calls, even within the same Action Gateway session. An execution time limit applies, including time spent calling tools.

A session’s [VPC attachment](https://docs.digitalocean.com/products/managed-agents/action-gateway/concepts/sessions/index.html.md#vpc-attachment) lets the sandbox access private resources, subject to their authentication and network controls.

## Advanced: Programmatic Tool Calling

With *programmatic tool calling*, the agent writes Python that calls tools and processes their results before returning output to the model. For example, fetch issues, filter them by date, and print a summary instead of returning every issue. Fewer model round trips and fewer tool-result tokens can reduce latency and inference costs.

The sandbox provides `invoke_digitalocean_tool(name, arguments)` for these calls. Use [Tool Search](https://docs.digitalocean.com/products/managed-agents/action-gateway/concepts/tool-search/index.html.md) to find tool names and input schemas. Check each call’s success or failure before using its output.

Calls use the session’s tool policy, provider connections, and output views. Running Python does not bypass approvals or provider authorization. Completed tool actions are not rolled back if a later step fails; check [retry and idempotency behavior](https://docs.digitalocean.com/products/managed-agents/action-gateway/concepts/reliable-execution/index.html.md) before repeating writes.

## Pricing

Code execution has separate compute and memory charges. Tools called from Python also incur their applicable invocation and provider charges. See [Action Gateway Pricing](https://docs.digitalocean.com/products/managed-agents/action-gateway/details/pricing/index.html.md).