Use Cases

See how teams use Cerver to safely execute code in production.

AI AGENTS

Code Interpreter for LLMs

Let your AI assistant write and execute Python code to answer questions, analyze data, and solve problems.

  • ChatGPT-style code execution
  • Data analysis and visualization
  • Mathematical computations
  • File processing and transformations
from cerver import Sandbox
from openai import OpenAI

sandbox = Sandbox()
client = OpenAI()

# AI generates code, Cerver runs it safely
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{
        "role": "user",
        "content": "Calculate compound interest"
    }],
    tools=[{"type": "function", ...}]
)

result = sandbox.run(generated_code)
print(result.output)
DATA SCIENCE

Interactive Data Analysis

Run pandas, numpy, and matplotlib in isolated environments. Perfect for data pipelines and exploratory analysis.

  • CSV/JSON processing
  • Statistical analysis
  • Chart generation
  • Machine learning inference
with Sandbox(engine="containers") as sandbox:
    sandbox.install("pandas matplotlib")
    sandbox.write_file("data.csv", csv_content)

    result = sandbox.run("""
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv(__sandbox_dir__ + '/data.csv')
print(df.describe())

df.plot(kind='bar')
plt.savefig(__sandbox_dir__ + '/chart.png')
""")

    chart = sandbox.read_file("chart.png")
EDUCATION

Coding Playgrounds

Build interactive coding environments for learning platforms, bootcamps, and technical interviews.

  • Real-time code execution
  • Isolated student environments
  • Automated grading
  • No infrastructure to manage
# Student submits solution
student_code = request.json["code"]

with Sandbox() as sandbox:
    # Run with timeout for safety
    result = sandbox.run(student_code)

    # Check against test cases
    test_result = sandbox.run("""
assert fibonacci(10) == 55
assert fibonacci(0) == 0
print("All tests passed!")
""")

    return {
        "output": result.output,
        "passed": test_result.exit_code == 0
    }
AUTOMATION

ETL & Data Pipelines

Run user-defined transformations on data without risking your infrastructure.

  • Custom data transformations
  • User-defined functions
  • Webhook processors
  • Scheduled jobs
# User defines their transformation
user_transform = """
def transform(data):
    return [
        {**row, 'total': row['qty'] * row['price']}
        for row in data
    ]
"""

with Sandbox() as sandbox:
    sandbox.write_file("input.json", json.dumps(data))

    result = sandbox.run(f"""
import json
{user_transform}

with open(__sandbox_dir__ + '/input.json') as f:
    data = json.load(f)

output = transform(data)
print(json.dumps(output))
""")
DEVTOOLS

Code Review & Testing

Automatically run and validate code snippets from PRs, documentation, or user submissions.

  • PR code validation
  • Documentation testing
  • Syntax checking
  • Security scanning
# Validate code from a pull request
for snippet in extract_code_blocks(pr_diff):
    with Sandbox() as sandbox:
        result = sandbox.run(snippet)

        if result.exit_code != 0:
            post_pr_comment(
                f"Code block failed:\n{result.error}"
            )
        else:
            print(f"✓ Snippet passed")
REAL-TIME

Streaming Output

Show users real-time progress for long-running tasks. Perfect for data processing, training, and batch jobs.

  • Live progress updates
  • Server-Sent Events
  • Long-running computations
  • Interactive debugging
with Sandbox() as sandbox:
    # Stream output in real-time
    for event in sandbox.run_stream("""
import time
for i in range(100):
    print(f"Processing batch {i}/100...")
    time.sleep(0.1)
print("Complete!")
"""):
        if event.type == "stdout":
            # Send to frontend via websocket
            websocket.send(event.data)
        elif event.type == "exit":
            print(f"Done: {event.code}")

Ready to build?

Get your API key and start executing code in seconds.

Get started free