Skip to main content
Your code starts a Modal sandbox and makes a OneCLI agent for it, on one vault. The sandbox can reach only OneCLI. Its HTTPS calls go through the gateway, which adds the vault’s key on the way out, so no key is ever in the sandbox.
Modal’s JavaScript SDK is in beta.

Before you start

  • A OneCLI managing key in ONECLI_API_KEY. Make one in the dashboard under Settings > API keys. It stays with your code: never put it in the sandbox.
  • Modal credentials in MODAL_TOKEN_ID and MODAL_TOKEN_SECRET, or in ~/.modal.toml.
  • Node.js 22 or later, or Python 3.11 or later.
  • The example uses your Personal vault and its Test key for httpbin.org, which every account starts with. Use any vault, and any host it has an item for.

Install

Example

Save the TypeScript as sandbox.mts and run npx tsx sandbox.mts, or the Python as sandbox.py and run python sandbox.py. It prints 200.

What goes where

The Sandboxes overview explains each value.

Good to know

  • The image needs curl. Slim images, such as debian:bookworm-slim and Modal’s debian_slim, lack it, so the example adds curl and ca-certificates. Modal builds the image the first time.
  • A tls route, not https. A tls route matches by host name on port 443 and never decrypts the connection, which is what the gateway needs.
  • Lifetime. A Modal sandbox lives 5 minutes unless you set timeoutMs in TypeScript, or timeout in seconds in Python, up to 24 hours. Keep the agent’s lifetime at least as long.
  • Node clients. Behind an allow list, Node’s http and https modules and axios fail, because they send no host name to the gateway. Give them agent.baseUrl(host) instead, or agent.base_url(host) in Python. See the SDK reference for TypeScript or Python.
  • Modal’s own key injection. Modal can also add a key to a sandbox’s calls itself, with header replacements on its https routes, in beta. See how OneCLI compares.

From a terminal

Modal sandboxes are made from code, so use the example above. For a sandbox of another provider, see From a terminal.

Versions

Written in December 2026 for @onecli-sh/sdk 4.1 and modal 0.12 in TypeScript, and for onecli-sdk 0.1 and modal 1.7 in Python.

Next steps