Skip to main content
Store a credential once, then attach it to any sandbox. On run_code / run_cmd (and on runtime run / runtime exec) it arrives as an environment variable. The key stays out of your source and out of the prompt.
Secret values are write-only. List and get return masked placeholders. Manage providers under Identity → Providers in the console, or with client.identity.providers.

Store a credential once

The secret key is the environment variable name (OPENAI_API_KEY). Saving the same key again replaces the value. The next run receives the current value. It is not written into the sandbox’s saved environment. Attach on create with providers=[...], or later with attach. After detach, the next run does not receive those secrets. An interactive shell does not receive them. Use run_code or run_cmd.

Add another key

Attach it to a new sandbox

Attach it to a running sandbox

Call an API with it

The snippet below runs Python inside the sandbox. Identity injects OPENAI_API_KEY as an env var on run_code / run_cmd (and on runtime run / runtime exec). The call leaves the sandbox, so the runtime also needs a network policy that allows api.openai.com on port 443.

Remove it

Update a secret

Python methods are on client.identity.providers. TypeScript uses camelCase (addSecret, listForRuntime, isActive).

Security best practices

Identity providers keep secrets out of your source tree and make rotation easier — but attaching secrets still injects those values into the sandbox as environment variables on run_code / run_cmd. Keeping the sandbox separate from your application does not stop a context-injected agent from reading os.environ, writing files, or sending data over the network.
Prefer keeping high-value credentials in tools that run outside the sandbox. Let the agent call those tools; do not put the raw key where code inside the sandbox can print or exfiltrate it. Attach secrets when the workload truly must authenticate from inside the runtime — and design for least privilege.

Safer patterns

  1. Authenticate outside the sandbox — your app or a host-side tool holds the API key; the sandbox only receives non-sensitive results.
  2. Narrow Identity secrets — one provider per integration, keys scoped to the minimum API surface, rotate often, detach when unused.
  3. Limit what can leave the box — use Limit outbound traffic to allowlist or block outbound destinations; monitor for unexpected destinations.
  4. Human review for risky actions — require approval before tool calls that spend money, change production data, or leave the sandbox.
  5. Treat sandbox I/O as hostile — validate outputs, redact secrets from logs, and never trust agent-generated commands blindly.
Short-lived or scoped credentials inside a sandbox are still readable by any code that runs there. If an attacker can steer the agent, they can usually read those values too. Injection into the runtime is a convenience tradeoff, not a security boundary.
For broader sandbox hardening, see Overview — Security best practices.

Next

Create Runtime

Create a sandbox and attach secrets

Limit outbound traffic

Allow only the hosts a secret should reach

Endpoints