Core Concepts
- Simple-to-use: Sandboxes are created, used, and destroyed seamlessly.
- Secure: They provide a safe boundary for running untrusted AI actions, like executing AI-generated code.
- Nested: You can run a Sandbox inside a data processing pipeline or an AI agent workflow.
Supported Runtimes
CPU Sandboxes
CPUSandbox is ideal for running lightweight code, data processing, or executing user-submitted scripts securely.
Create Hardware-Isolated Sandbox and Run Code
GPU Sandboxes
GPUSandbox provides fast access to secure, hardware-isolated VMs with GPUs. They include automatic storage for self-hosted models (perfect for agents) and support concurrent requests on the same GPU for significant cost savings.
Run Inference
You can execute scripts directly on the GPU by providing a code file or script in thecreate method.
Providing Code and Models
There are three ways to provide the code and models you want the Sandbox to use:Code
1. Relative Path Reference a file relative to your current working directory.Models
Models can also be referenced by path when creating a GPU Sandbox. 1. Relative PathSandbox Management
Delete and Timeouts
You have the option to manually calldelete() to clean up a Sandbox when you’re ready.
If you don’t call delete(), the sandbox will be automatically cleaned up after the period you set for the timeout argument.
- Default Timeout: If you don’t set a
timeoutargument, the default is 1 minute. - Auto-Cleanup: The sandbox is destroyed automatically after the timeout expires.
JavaScript
Sandbox Configuration
You can customize the resources and environment for your sandboxes.Parameters
GPU Sandbox (Python SDK)- language:
python(more coming soon). - memory: RAM allocation (e.g.,
"65536MB"). - gpu: GPU Type (e.g.,
T4G). - requirements: List of Python packages (e.g.,
['transformers']). - model: Path to model can be local or remote (e.g., Hugging Face
Qwen/Qwen3-8B).
- runtime: (e.g.,
node,python). - memory: RAM allocation.
- timeout: Max execution time in seconds.
Runtime Specifics
Python Requirements You can specify dependencies in your code or via arequirements.txt.
Nested Sandboxes
One of the most powerful features of Buildfunctions is Nested Orchestration. You can deploy a top-level Function (e.g., a Node.js API) that spins up child Sandboxes (e.g., Python GPU workers) to handle requests.Example Architecture
- Top-Level Function: Receives an HTTP request.
- Child Sandbox: The function spins up a
GPUSandboxto run a customized model. - Result: The sandbox returns the inference result to the function, which responds to the user.
- Cleanup: The sandbox is destroyed, ensuring clean resource usage.
Advanced Example: Python Agent
This example demonstrates an advanced agentic workflow: Code Generation with Reward Scoring. The agent uses Claude to generate a Python function, then immediately spins up a secureCPUSandbox to test the code against a set of unit tests (the reward function). This allows the agent to verify the correctness of its output before proceeding.
This example requires an
ANTHROPIC_API_KEY to be available in your environment.