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.
Store a secret once, attach it to the runtime, and it arrives as an environment variable on each run.
1Identity providerStored secretsCreated once. Rotated in place.
API_KEYDATABASE_URL
attach
2RuntimeSandboxThe value is not saved on the runtime.
run_coderun_cmd
each run
3Inside the processEnvironment variablesResolved when the command starts.
$API_KEY$DATABASE_URL
Injected on each run_code and run_cmdList and get stay maskedAfter a rotate, the next run picks it up
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
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 injectsOPENAI_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 onclient.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 onrun_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.
Safer patterns
- Authenticate outside the sandbox — your app or a host-side tool holds the API key; the sandbox only receives non-sensitive results.
- Narrow Identity secrets — one provider per integration, keys scoped to the minimum API surface, rotate often, detach when unused.
- Limit what can leave the box — use Limit outbound traffic to allowlist or block outbound destinations; monitor for unexpected destinations.
- Human review for risky actions — require approval before tool calls that spend money, change production data, or leave the sandbox.
- Treat sandbox I/O as hostile — validate outputs, redact secrets from logs, and never trust agent-generated commands blindly.
Next
Create Runtime
Create a sandbox and attach secrets
Limit outbound traffic
Allow only the hosts a secret should reach