Skip to main content
Moru applies rate limits to ensure fair usage and platform stability.

Rate Limit Headers

API responses include rate limit headers:
HeaderDescription
X-RateLimit-LimitMaximum requests per window
X-RateLimit-RemainingRemaining requests in window
X-RateLimit-ResetUnix timestamp when window resets

Default Limits

ResourceLimit
Sandbox creation60 per minute
API requests1000 per minute
Template builds10 per hour

Handling Rate Limits

When you exceed rate limits, you’ll receive a 429 Too Many Requests response.
import time
from moru import Sandbox
from moru.exceptions import SandboxException

def create_with_backoff(max_retries=5):
    for attempt in range(max_retries):
        try:
            return Sandbox.create()
        except SandboxException as e:
            if "rate limit" in str(e).lower():
                wait = 2 ** attempt  # Exponential backoff
                print(f"Rate limited, waiting {wait}s...")
                time.sleep(wait)
            else:
                raise
    raise Exception("Max retries exceeded")

Best Practices

1. Implement Retry Logic

Always implement exponential backoff for rate limit errors:
import time

def with_retry(fn, max_retries=5):
    for attempt in range(max_retries):
        try:
            return fn()
        except Exception as e:
            if "rate limit" in str(e).lower() and attempt < max_retries - 1:
                time.sleep(2 ** attempt)
            else:
                raise

2. Batch Operations

Reduce API calls by batching:
# Instead of multiple writes
for file in files:
    sandbox.files.write(file["path"], file["data"])

# Use batch write
sandbox.files.write_files(files)

3. Reuse Sandboxes

Keep sandboxes alive instead of creating new ones:
# Create once
sandbox = Sandbox.create(timeout=3600)

# Reuse for multiple operations
for task in tasks:
    result = sandbox.commands.run(task)

# Clean up when done
sandbox.kill()

4. Cache Template IDs

Avoid repeated template lookups:
# Look up once
template_id = get_template_id("my-template")

# Reuse the ID
for _ in range(10):
    sandbox = Sandbox.create(template_id)

Increasing Limits

Need higher rate limits? Contact us at hi@moru.io.

Next Steps