Skip to main content
Get up and running with GravixLayer Sandbox in minutes. This guide covers installation, authentication, and your first sandbox execution.

Prerequisites

  • Python 3.7+ or Node.js 16+
  • GravixLayer API key

Installation

# Install via pip
pip install gravixlayer

# Verify installation
python -c "import gravixlayer; print(gravixlayer.__version__)"

Authentication

Set your API key as an environment variable:
set GRAVIXLAYER_API_KEY=your_api_key_here
Security Best Practice: Always use environment variables for API keys. Never hardcode them in your source code or commit them to version control.

Your First Sandbox

Method 1: Simple Creation

# Create sandbox
gravixlayer sandbox create --provider gravix --region eu-west-1

# Run code (replace YOUR_SANDBOX_ID)
gravixlayer sandbox code YOUR_SANDBOX_ID "print('Hello, GravixLayer!')"
Output:
Created sandbox: 550e8400-e29b-41d4-a716-446655440000
Hello, GravixLayer!

Method 2: Custom Configuration

gravixlayer sandbox create --provider gravix --region eu-west-1 --timeout 600 --template python-base-v1
Output:
Created sandbox: 5a44cb3f-76b3-4398-9a9a-4898c036bf19
   Template: python-base-v1
   Status: running
   Resources: 2 CPU, 1024MB RAM
   Started: 2025-10-28T09:55:28.349147173Z
   Timeout: 2025-10-28T10:05:28.349147173Z

Basic Operations

Running Code

gravixlayer sandbox code YOUR_SANDBOX_ID "print('Hello World!')"

gravixlayer sandbox code YOUR_SANDBOX_ID "
import math
result = math.sqrt(16)
print(f'Square root of 16 is {result}')
"
Output:
Hello World!
Square root of 16 is 4.0

Executing Commands

with Sandbox.create() as sandbox:
    result = sandbox.run_command("python", ["--version"])
    print(result.stdout)
    
    result = sandbox.run_command("ls", ["-la", "/home/user"])
    print(result.stdout)
Output:
Python 3.11.14

ls: /home/user: No such file or directory

Working with Files

from gravixlayer import Sandbox

with Sandbox.create() as sandbox:
    sandbox.write_file("/home/user/hello.txt", "Hello, World!")
    
    content = sandbox.read_file("/home/user/hello.txt")
    print(content)
    
    files = sandbox.list_files("/home/user")
    print(files)
Output:
Hello, World!
['hello.txt']

Next Steps