What are sandbox templates?
Sandbox templates are pre-configured images that serve as blueprints for creating sandboxes. Each template includes:- Base environment: Operating system and runtime configurations
- Tools: Languages, frameworks, and development tools
- Configuration: Environment variables, startup scripts, …
- Resources: Memory allocated
How sandbox templates work
- Initial setup: Follow this guide to create your sandbox template for the first time. This process also creates your first sandbox instance using this template.
- Build phase: Your Dockerfile is used to create a container with all required tools and configurations.
- Initialization phase: The sandbox API is injected and startup commands are executed.
- Instantiation: New sandboxes can be spawned from this template in seconds.
Create a sandbox template
1. Initialize a template
Start by creating a new sandbox template using the Blaxel CLI:2. Customize the Dockerfile
The Dockerfile is the heart of your template. It defines what will be available in your sandbox environment.Basic template structure
3. Configure template settings
Theblaxel.toml
file defines your template’s runtime configuration:
4. Define initialization
Theentrypoint.sh
script runs when a sandbox is created from your template:
5. Build and test locally
Before creating the template on Blaxel, test it locally:6. Deploy the template
Once satisfied with your configuration, create the template on Blaxel:- Build your Docker image
- Push it to Blaxel’s registry
- Return an image ID you can use for creating sandboxes
Use a template
Once your template is created, spawn new sandboxes instantly by using the image ID:Update a template
To update an existing template:- Modify your Dockerfile or configuration
- Rebuild locally to test changes
- Deploy the new version:
Best practices
1. Optimize for cold starts
- Use smaller base images (Alpine when possible)
- Minimize layers in Dockerfile
- Pre-install only essential packages
- Defer optional installations to runtime
2. Cache dependencies
3. Security considerations
- Don’t include secrets in templates
- Use Blaxel’s secrets management for sensitive data
- Keep base images updated
- Scan for vulnerabilities regularly
4. Resource optimization
Choose appropriate resources for your use case:Use Case | Memory |
---|---|
Light development | 2GB |
Small web application | 4GB |
Full-stack web | 8GB |