Introducing Render Sandboxes: a computer for every agent.

Learn more

Giving an AI agent a Render API key that can only run sandboxes

Your agent already creates sandboxes in a sandbox group you set up. The remaining question is which API key it holds. This guide shows you how to give it a key that creates, runs, and terminates sandboxes and does nothing else in your workspace: no services, no deploys, no databases.

For background on sandboxes and why agents should run generated code in them, read What are sandboxes, and why your agents should use them. For the general difference between classic and scoped keys, read Replacing classic Render API keys with scoped API keys.

“

Render Sandboxes is in public beta, and APIs, defaults, and limits might change during the beta period.

Grant only the Sandboxes permissions

Create a scoped API key with only these permissions.

Permission area
Setting
Why the agent needs it (or doesn't)
Sandboxes
Read & write: on
The agent creates and terminates sandboxes. This also covers sandbox groups and snapshots if your agent manages them.
Sandboxes
Execute: on
The agent runs commands and uploads or downloads files.
Sandboxes
Manage sandbox credentials: off
Leave this off.
Services
Off
Not part of the agent's job. This area also covers environment variables and secret files.
Deploys
Off
Not part of the agent's job.
Postgres
Off
Not part of the agent's job.

On the key form, start from the Clear all preset, turn on only Sandboxes Read & write and Execute, and leave every other permission area off, including Workflows, Key Value, and the rest.

Permissions you withhold limit what a compromised agent, a prompt-injected tool call, or a leaked key can do.

Create the key and wire it into your agent

When you create the key, select the workspace that holds your sandbox group. A scoped key only reaches the workspace you created it in, so a key from another workspace fails. Both SDKs read the API key from RENDER_API_KEY and the workspace from RENDER_WORKSPACE_ID by default, so set RENDER_WORKSPACE_ID to that same workspace's ID. If the agent uses the CLI, also run render workspace set "$RENDER_WORKSPACE_ID".

The TypeScript SDK's Render client reads its API key from the RENDER_API_KEY environment variable by default. If you don't provide a key, the client throws a RenderError.

A minimal .env looks like this. Replace the placeholder values with your own:

The SDKs read these values from the process environment, not from the file, so load the .env with a dotenv loader or your process manager before you construct the client.

Group IDs start with sbg-. Put these values only in the orchestrator process's environment, never inside a sandbox.

Create, run, and terminate a sandbox

The TypeScript SDK ships as @renderinc/sdk at version 1.9.0 or later. All of its sandbox methods return Promises. The Python SDK requires render>=1.9.0, which needs Python 3.11 or later.

The examples below follow the documented sandbox lifecycle: create a sandbox, execute a command in it, then terminate it. They use the SDK's create, exec, and terminate calls. Both pass wait: true (wait=True in Python), because without it create returns before the sandbox is running. The command is echo hello, the same command the Executing commands docs use. exec streams output events followed by a final exit event that carries the command's exit code. A nonzero exit code doesn't throw or raise in the SDK, so the examples check the exit event and fail the task themselves. For every option, see the TypeScript SDK reference or the Python SDK reference.

Each example follows the same three steps:

  1. Create. The agent creates a sandbox in your group. Pass the group ID explicitly. If you create a sandbox without specifying a group, Render uses your workspace's default group.
  2. Run. The agent runs one command and prints its output.
  3. Terminate. The finally block terminates the sandbox even when the command fails.

You also configure network access and environment variables in the creation options. The next two sections cover both.

Restrict the network

A new sandbox allows outbound traffic to any destination by default, so set a network policy on every sandbox your agent creates. Generated code with open outbound access can send whatever it reads to any host. You can configure a sandbox to allow outbound traffic to a specific set of destinations, or to none at all.

Pick one of two shapes, depending on the task:

  • Deny all. Use this for tasks that only compute on files you upload. In TypeScript, pass networkPolicy: { type: 'deny-all' } when you create the sandbox. In Python, pass network_policy="deny-all".
  • Allowlist. List only the hosts the task needs, such as your package registry's hosts or a model API host. In both SDKs, set the network policy type to allow-list and provide between 1 and 100 rules, and the sandbox blocks all other outbound traffic. Each rule is a lowercase hostname with no scheme, port, or path. An exact hostname doesn't include its subdomains, while a wildcard such as *.example.com does. An allowlist only permits HTTPS destinations, so Render blocks traffic that uses any other protocol, even to an allowed host.

The following snippets show the allowlist shape in each SDK, allowing api.github.com and subdomains of pypi.org:

Start from deny-all or a minimal allowlist. Add a host only when a task fails because it needs that host. For the exact allowlist rule format, see configuring sandbox behavior.

Sandboxes can't yet reach your other Render services or datastores over private networking. Don't design an agent workflow that depends on it.

Pass only the secrets the task needs

Treat every environment variable you set at creation as readable by any command the agent runs in that sandbox. Agent-generated code can print, log, or send those values anywhere its network policy allows.

Follow these rules:

  • Pass only the values the specific task needs.
  • Never pass RENDER_API_KEY into a sandbox. It belongs to the orchestrator.
  • Prefer short-lived or narrowly scoped third-party tokens.

Credential brokering isn't yet generally available. Until it is, environment variables are how secrets reach a sandbox, so choose them deliberately.

Plan for concurrency and rate limits

Workspace plan
Default concurrent sandboxes per sandbox group
Hobby
100
Pro and above
1,000

While a group is at its concurrency limit, requests to create or resume a sandbox fail with HTTP 429. Suspended sandboxes don't count toward the limit.

Handle 429 explicitly with backoff or a queue. Terminate sandboxes promptly to reclaim capacity, and lower an individual group's concurrency limit if you want to cap a single agent.

Sandbox API operations also have separate default rate limits. These limits apply per user, and all of that user's API keys share them. For example, you can send up to 100 sandbox creation requests per minute. Scoping the key's permissions doesn't give it its own rate-limit budget, so a runaway agent draws from the same budget as the key creator's other keys. Cap the agent's request rate in your orchestrator so it can't starve your CI or your own CLI sessions.

Troubleshooting

  • The client throws on startup. RENDER_API_KEY isn't set in the host process.
  • Sandboxes land in the wrong group. You didn't pass a group ID, so Render used the default group.
  • Creates fail with 429. You've hit either the group's concurrency limit or a rate limit. Back off, then check for sandboxes your agent never terminated.
  • Requests fail with an authorization error. Confirm the key has Sandboxes Read & write and Execute turned on. If creating a sandbox works but running a command fails, check Execute first. Then confirm you created the key in the workspace that holds the sandbox group and that RENDER_WORKSPACE_ID matches it.
  • Commands can't reach a host. Add that host to the allowlist, and only if the task needs it.

Before you rely on it in production

Keep these constraints in mind:

  • Render Sandboxes is in public beta, and all limits might change.
  • Credential brokering isn't yet generally available.
  • Sandboxes don't yet support private networking to other Render services and datastores.

Next, read the Sandboxes limits page for the full rate-limit table, and see Executing commands to learn how to handle command failures.

Frequently asked questions