@teamnhz/sandbox-platform-cli
v0.1.0
Published
CLI tool for managing sandbox platform resources
Readme
Sandbox Platform CLI
A command-line interface for managing the E2B-like sandbox platform. Create, manage, and execute code in secure, isolated environments from your terminal.
Installation
# Install globally
npm install -g @sandbox-platform/cli
# Or use with npx
npx @sandbox-platform/cli --helpQuick Start
- Authenticate:
sbp auth login- Create a sandbox:
sbp sandbox create --tech-stack python --name my-project- Execute code:
sbp sandbox execute <sandbox-id> "print('Hello from sandbox!')"- List sandboxes:
sbp sandbox listCommands
Authentication
# Login with API key
sbp auth login
# Check authentication status
sbp auth whoami
# Logout
sbp auth logout
# Show current configuration
sbp auth configSandbox Management
# Create sandbox
sbp sandbox create [options]
-t, --tech-stack <stack> Technology stack (nodejs, python, go, etc.)
-n, --name <name> Project name
-f, --files <pattern> Upload files matching pattern
--template <template> Use template
--cpu <cpu> CPU limit (vCPUs)
--memory <memory> Memory limit (MB)
--timeout <timeout> Timeout in seconds
--env <KEY=VALUE> Environment variables
--no-wait Don't wait for sandbox to be ready
# List sandboxes
sbp sandbox list
-u, --user-id <userId> Filter by user ID
-f, --format <format> Output format (table|json|yaml)
# Get sandbox details
sbp sandbox get <id>
# Execute code
sbp sandbox execute <id> [code]
-l, --language <language> Programming language
-f, --file <file> Execute code from file
-s, --stream Stream execution output
-t, --timeout <timeout> Execution timeout
# Delete sandbox
sbp sandbox delete <id>
-f, --force Force deletion without confirmation
# Get logs
sbp sandbox logs <id>
-n, --lines <lines> Number of lines to showTemplates
# List available templates
sbp templates --list
# Get template details
sbp templates --get <id>Configuration
# List all configuration
sbp config --list
# Get specific value
sbp config --get <key>
# Set configuration value
sbp config --set <key=value>
# Reset configuration
sbp config --resetExamples
Create and Use a Python Sandbox
# Create sandbox with template
sbp sandbox create \
--tech-stack python \
--name data-analysis \
--template data-science \
--env "API_KEY=secret123"
# Execute code with streaming output
sbp sandbox execute sandbox-123 --stream \
"
import pandas as pd
import numpy as np
data = pd.DataFrame({
'x': np.random.randn(100),
'y': np.random.randn(100)
})
print(data.describe())
"
# Execute code from file
sbp sandbox execute sandbox-123 --file analysis.py
# Clean up
sbp sandbox delete sandbox-123 --forceBatch Operations
# List all running sandboxes
sbp sandbox list --format json | jq '.[] | select(.status == "running")'
# Delete all stopped sandboxes
sbp sandbox list --format json | \
jq -r '.[] | select(.status == "stopped") | .id' | \
xargs -I {} sbp sandbox delete {} --forceWorking with Files
# Create sandbox with initial files
sbp sandbox create \
--tech-stack nodejs \
--files "src/**/*.js,package.json" \
--name web-app
# Execute with environment variables
sbp sandbox execute sandbox-456 \
--env "NODE_ENV=development" \
--env "PORT=3000" \
"npm start"Configuration
The CLI stores configuration in your home directory. You can configure:
apiKey: Your API key for authenticationbaseUrl: API base URL (default: https://api.sandboxplatform.com)defaultTechStack: Default technology stackoutputFormat: Default output format (table, json, yaml)
# Set default tech stack
sbp config --set defaultTechStack=python
# Set custom API URL
sbp config --set baseUrl=https://my-sandbox-api.com
# Set default output format
sbp config --set outputFormat=jsonOutput Formats
The CLI supports multiple output formats:
Table (default)
sbp sandbox list
┌─────────────┬─────────┬─────────────┬─────────────────────┬──────┐
│ ID │ Status │ Tech Stack │ Created At │ URLs │
├─────────────┼─────────┼─────────────┼─────────────────────┼──────┤
│ sandbox-123 │ running │ python │ 2023-12-01 10:30:00 │ 2 │
└─────────────┴─────────┴─────────────┴─────────────────────┴──────┘JSON
sbp sandbox list --format json
[
{
"id": "sandbox-123",
"status": "running",
"techStack": "python",
"createdAt": "2023-12-01T10:30:00Z",
"urls": {
"api": "https://...",
"preview": "https://..."
}
}
]YAML
sbp sandbox list --format yaml
- id: sandbox-123
status: running
techStack: python
createdAt: 2023-12-01T10:30:00Z
urls:
api: https://...
preview: https://...Tech Stacks
Supported technology stacks:
nodejs- Node.js with npmpython- Python with pipgo- Go with modulesjava- Java with Mavenreact-vite- React with Vitevue-vite- Vue with Vitenextjs- Next.js frameworksveltekit- SvelteKit frameworkastro- Astro frameworkremix- Remix frameworkqwik- Qwik frameworkexpo- React Native with Expo
Error Handling
The CLI provides detailed error messages and exit codes:
0- Success1- General error2- Authentication error3- Resource not found4- Validation error
Development
# Install dependencies
npm install
# Build CLI
npm run build
# Test locally
npm run dev
# Link for global testing
npm linkAliases
You can use these shorter aliases:
sbpinstead ofsandbox-platformsbinstead ofsandboxlsinstead oflistrminstead ofdeletetplinstead oftemplates
License
MIT
