Sandbox

Anonymous code execution with zero setup

Overview

The anonymous sandbox lets anyone execute code without an API key or account. It supports TypeScript, JavaScript, and Python. Rate limited to 10 executions per day per IP address.

This is available on r.sandbox.

For project-scoped sandboxes (with persistent filesystem, databases, and storage), see Projects & Deploy. This page covers the anonymous/free sandbox only.

Quick start

1import { Recursiv } from '@recursiv/sdk';
2
3const r = new Recursiv({ anonymous: true });
4
5const { data, meta } = await r.sandbox.execute({
6 code: 'console.log("Hello, world!")',
7 language: 'typescript',
8});
9
10console.log(data.output); // "Hello, world!\n"
11console.log(data.exitCode); // 0
12console.log(data.executionTime); // milliseconds
13console.log(meta.remaining_executions); // 9 (out of 10/day)

Method

r.sandbox.execute(input)

Execute code in an isolated sandbox environment.

Input:

FieldTypeRequiredDefaultDescription
codestringYesThe code to execute.
language'typescript' | 'javascript' | 'python'No'typescript'Programming language.

Returns: SandboxResponse

1interface SandboxResponse {
2 data: {
3 output: string; // Combined stdout/stderr
4 exitCode: number; // 0 on success, non-zero on error
5 executionTime: number; // Execution time in milliseconds
6 error?: string; // Error message if execution failed
7 };
8 meta: {
9 sandbox_id: string;
10 remaining_executions: number; // Remaining executions today
11 signup_url: string; // URL to sign up for unlimited access
12 };
13}

Anonymous mode

The sandbox is designed for anonymous access. Pass anonymous: true to the constructor to skip API key validation:

1const r = new Recursiv({ anonymous: true });

When anonymous is true, the SDK does not require or send an API key. Only the r.sandbox.execute() method is available in this mode — all other resources require authentication.

Supported languages

TypeScript

1const { data } = await r.sandbox.execute({
2 code: `
3 interface User {
4 name: string;
5 age: number;
6 }
7
8 const user: User = { name: 'Alice', age: 30 };
9 console.log(JSON.stringify(user));
10 `,
11 language: 'typescript',
12});
13
14console.log(data.output); // {"name":"Alice","age":30}

JavaScript

1const { data } = await r.sandbox.execute({
2 code: `
3 const numbers = [1, 2, 3, 4, 5];
4 const sum = numbers.reduce((a, b) => a + b, 0);
5 console.log('Sum:', sum);
6 `,
7 language: 'javascript',
8});
9
10console.log(data.output); // Sum: 15

Python

1const { data } = await r.sandbox.execute({
2 code: `
3import json
4
5data = {"message": "Hello from Python", "numbers": list(range(5))}
6print(json.dumps(data))
7 `,
8 language: 'python',
9});
10
11console.log(data.output); // {"message": "Hello from Python", "numbers": [0, 1, 2, 3, 4]}

Rate limits

The anonymous sandbox is rate limited to 10 executions per day per IP address. The meta.remaining_executions field tells you how many you have left.

1const { meta } = await r.sandbox.execute({
2 code: 'console.log("test")',
3});
4
5if (meta.remaining_executions === 0) {
6 console.log(`Daily limit reached. Sign up at ${meta.signup_url}`);
7}

When the limit is reached, the SDK throws a RateLimitError:

1import { RateLimitError } from '@recursiv/sdk';
2
3try {
4 await r.sandbox.execute({ code: 'console.log("test")' });
5} catch (err) {
6 if (err instanceof RateLimitError) {
7 console.log('Daily sandbox limit reached.');
8 console.log('Upgrade:', err.upgradeUrl);
9 }
10}

Error handling

1const { data } = await r.sandbox.execute({
2 code: 'throw new Error("something broke")',
3 language: 'typescript',
4});
5
6if (data.exitCode !== 0) {
7 console.error('Execution failed:');
8 console.error(data.output); // Contains the error stack trace
9 console.error(data.error); // Error summary if available
10}

Use cases

The anonymous sandbox is ideal for:

  • Try-before-you-buy: Let users experiment with the platform without creating an account.
  • Code playgrounds: Embed a code editor on your website that executes code via the API.
  • AI agent tools: Give LLMs the ability to run code without provisioning infrastructure.
  • Quick prototyping: Test ideas without setting up a full project.

For production workloads, use project sandboxes with r.projects.executeCode() which have no daily limits and access to databases, storage, and a persistent filesystem.