Skip to main content

Step 1: Create an Account

Sign up for a free Moru account at moru.io/dashboard.

Step 2: Get Your API Key

  1. Go to the API Keys tab in your dashboard
  2. Click Create API Key
  3. Copy your new API key (you won’t be able to see it again)

Step 3: Install the SDK

Requirements: Python 3.8+ or Node.js 18+
pip install moru

Step 4: Set Your API Key

export MORU_API_KEY=your_api_key_here

Step 5: Create a Sandbox and Run Commands

from moru import Sandbox

# Create a sandbox with the default 'base' template
sandbox = Sandbox.create()
print(f"Sandbox created: {sandbox.sandbox_id}")

# Run a command
result = sandbox.commands.run("echo 'Hello, World!'")
print(f"Output: {result.stdout}")
print(f"Exit code: {result.exit_code}")

# Write a file
sandbox.files.write("/tmp/hello.txt", "Hello from Moru!")

# Read it back
content = sandbox.files.read("/tmp/hello.txt")
print(f"File content: {content}")

# List directory contents
entries = sandbox.files.list("/tmp")
for entry in entries:
    print(f"  {entry.name} ({entry.type})")

# Clean up
sandbox.kill()
print("Sandbox terminated")

Using Async (Python)

For async applications, use AsyncSandbox:
import asyncio
from moru import AsyncSandbox

async def main():
    sandbox = await AsyncSandbox.create()

    result = await sandbox.commands.run("python3 --version")
    print(result.stdout)

    await sandbox.kill()

asyncio.run(main())

Streaming Command Output

Stream output in real-time for long-running commands:
from moru import Sandbox

sandbox = Sandbox.create()

# Stream output as it arrives
sandbox.commands.run(
    "for i in 1 2 3; do echo $i; sleep 1; done",
    on_stdout=lambda data: print(f"stdout: {data}"),
    on_stderr=lambda data: print(f"stderr: {data}"),
    timeout=30
)

sandbox.kill()

Using a Custom Template

Create a sandbox with a specific template. You can create custom templates with pre-installed dependencies via the dashboard or CLI.
from moru import Sandbox

# Use a custom template (create one in the dashboard first)
sandbox = Sandbox.create("my-template")

result = sandbox.commands.run("echo 'Running in custom template'")
print(result.stdout)

sandbox.kill()

Next Steps