A windswept bonsai on a floating island

Get to know Cadenya

We’re developers who love to build. We set out to create a yes-code platform that makes building agents feel like the best parts of building software.

Cloudflare Sandbox SDK for AI agents (2026)

Cloudflare Sandbox SDK

By Cadenya

The Cloudflare Sandbox SDK runs an AI agent’s code in Cloudflare Containers, and Containers and Sandboxes have been generally available since April 13, 2026. Containers pricing bills every 10 ms a container runs on the $5 Workers Paid plan, each instance is a Firecracker microVM, and outbound egress is off until your Worker allows it with enableInternet or an outbound handler. Sandbox SDK 1.0 shipped on September 30, 2026: your own Durable Object starts the container and runs commands through this.ctx.container. Cadenya is a hosted agent loop that calls a Cloudflare sandbox as a tool set, and a coding agent can set it up with no account, in a temporary workspace you claim later.

This guide gives the agent a Bare tool called run_code and answers each call from your own backend. A small worker reads the objective’s events and sends the code to a Cloudflare Worker you deploy. That Worker runs it in a Linux container, one per objective, and the worker sends the output back through the API. A bearer token guards the Worker, and the container starts with no internet access.

If you’d rather have the agent call your Worker directly, an HTTP tool set does that, and that variant comes after the run. The same setup works with E2B, Daytona and Blaxel, and Sandboxes for running agent-generated code compares them. This page covers the Sandbox SDK and Containers. For AIChatAgent, Think and tool approval in the Agents SDK, see the Cloudflare Agents SDK guide. What Cadenya adds to a Cloudflare sandbox is at the end.

Every price and limit below comes from each vendor’s own pages, checked on November 11, 2026.

Cloudflare Sandbox SDK at a glance

Cloudflare Sandbox SDK and ContainersWith Cadenya
StatusContainers and Sandboxes GA since April 13, 2026. Sandbox SDK 1.0 since September 30, 2026@cadenya/cadenya 1.9.0, and 1.9.0 in every language
PricingBilled every 10 ms a container runs: $0.000020 a vCPU second, $0.0000025 a GiB second of memory, $0.00000007 a GB second of disk past the included usage. Needs Workers Paid, $5 a monthFree for 1,000 loops a month, $49 a month for 50,000, then $0.0015 a loop
Instance typeslite (1/16 vCPU, 256 MiB) to standard-4 (4 vCPU, 12 GiB, 20 GB disk), or a custom sizeThe Durable Object passes instance to start(), so each objective’s sandbox gets the size you pick
IsolationEach instance is a Firecracker microVM with its own kernel and networkThe code runs in the container your Durable Object starts for each objective
Network egressenableInternet: false by default. Outbound handlers in your Worker allow hosts and add credentialsThe container starts offline, and requiresApproval lets a person read the code first
PlacementNearest location with the image. Region and jurisdiction constraints apply to apps on the default scheduling policyYour worker reaches the sandbox through your Worker’s URL, wherever Cloudflare runs it
LanguagesA Worker in JavaScript or TypeScript. The container runs any language your image hasCadenya SDKs for TypeScript, Python, Ruby and Go, all Apache-2.0
Latest package@cloudflare/sandbox 1.0.3 (October 22, 2026), Wrangler 4.160.1Configs apply with cadenya config apply or a GitHub Action

Is the Cloudflare Sandbox SDK GA? Sandbox SDK 1.0 and Containers

Cloudflare’s changelog for April 13, 2026 says “Cloudflare Containers and Sandboxes are now generally available.” Sandbox SDK 1.0 followed on September 30, 2026, and the durable_object scheduling policy it runs on is in public beta. The 1.0 release changed the shape of the code. In 0.x, the Sandbox class from the package was your Durable Object. In 1.0, you write the Durable Object, and it calls the container directly through this.ctx.container, which runs commands, intercepts outbound requests and saves snapshots.

So the @cloudflare/sandbox package got smaller. Version 1.0.3 (Apache-2.0 on npm) holds three helpers, Files, S3Mount and DirectoryBackup, and the runner below needs none of them. Apps on 0.x keep running, and Cloudflare ships 0.x bug and security fixes until December 31, 2026.

Cloudflare’s other sandbox, a Dynamic Worker, runs JavaScript, Python or WebAssembly in a V8 isolate against methods your Worker passes in. This guide uses a container, because agent code tends to expect Linux, pip and files.

Cloudflare Containers pricing and instance types

Containers are “billed for every 10ms that they are actively running,” on the $5 a month Workers Paid plan. The plan includes 25 GiB-hours of memory, 375 vCPU-minutes and 200 GB-hours of disk a month. Past that, memory costs $0.0000025 a GiB second, CPU $0.000020 a vCPU second, and disk $0.00000007 a GB second. Memory and disk follow the instance type you provision, while CPU counts only active use. Egress costs $0.025 a GB in North America and Europe after 1 TB a month. Each container also has its own Durable Object, billed at Workers and Durable Objects rates.

The instance type sets the size:

Instance typevCPUMemoryDisk
lite1/16256 MiB2 GB
standard-11/24 GiB8 GB
standard-216 GiB12 GB
standard-328 GiB16 GB
standard-4412 GiB20 GB

A sandbox passes the name as instance to start(), and it defaults to lite. A custom object with vcpu, memoryMib and diskMb works too. (The basic type, 1/4 vCPU and 1 GiB, is set in Wrangler for apps on the default scheduling policy.) An idle instance still bills memory and disk, so the runner below stops each container when the agent’s turn ends.

Cloudflare Sandbox outbound egress control: enableInternet and outbound handlers

A container “starts with enableInternet: false by default, so it cannot reach the Internet.” To let it reach one host, register an outbound handler for that hostname. The handler is a WorkerEntrypoint in your Worker, so it can check each request, add a credential the container never sees, and forward it. Here’s the allowlist pattern from Cloudflare’s “Handle outbound traffic” page:

const ALLOWED_HOSTS = ["allowed.com"];

export class AllowHosts extends WorkerEntrypoint<Env> {
  fetch(request: Request): Promise<Response> | Response {
    if (!ALLOWED_HOSTS.includes(new URL(request.url).hostname)) {
      return new Response("Forbidden", { status: 403 });
    }
    return fetch(request);
  }
}

// In the Durable Object, before start():
for (const host of ALLOWED_HOSTS) {
  await container.interceptOutboundHttp(host, this.ctx.exports.AllowHosts);
  await container.interceptOutboundHttps(host, this.ctx.exports.AllowHosts);
}

Targets take hostname globs such as *.example.com, and interceptOutboundHttp also takes IP addresses and CIDR ranges. For HTTPS, the container must trust the CA file at /etc/cloudflare/certs/cloudflare-containers-ca.crt. Cloudflare’s advice is to keep internet access off when you use a handler, because with it on, every connection the handler doesn’t cover goes out directly.

Isolation and placement

“Each container instance runs in a Firecracker microVM with its own kernel and network,” and your image runs as a Linux container inside that VM. Build images for linux/amd64. Cold starts “can often be in the 1-3 second range,” depending on image size and what the entrypoint does. HTTP from the internet reaches an instance only through your Worker.

By default, a container starts in the nearest location that has its image, and later requests for that instance go to the same place while it runs. Placement constraints narrow that down. regions takes ENAM, WNAM, EEUR, WEUR, APAC, SAM, ME, OC and AFR, and jurisdiction: "eu" maps to EEUR and WEUR for EU data residency. They go in a Container application’s constraints in Wrangler, and Wrangler’s reference lists them for the default scheduling policy.

How a bare tool runs code in your sandbox

A Bare tool set holds tools with no execution adapter. Cadenya stores the tool, shows it to the model, and waits for you to supply each result. Here’s one run_code call from start to finish:

  1. The agent calls run_code with a Python program as its code argument.
  2. The loop records the call, writes a toolCalled event to the objective, and pauses until the call gets content.
  3. Your worker reads that event from the objective’s event stream and posts the code to your Cloudflare Worker, which starts a container on the first call and runs it.
  4. The worker sends stdout, stderr and any error back with setToolCallContent, and the agent reads them on its next loop.

The runner token lives only in your worker’s environment and in a Worker secret. The container never holds it, and it never needs to reach the agent loop.

The worker keeps one sandbox per objective, so a file the agent writes in one call is still there in the next. It stops the container when the agent’s turn ends.

The agent, the tool and the variation as config files

Cadenya’s CLI applies resources from YAML files in .cadenya/, with settings in cadenya.yaml. Each file is one resource, and a child directory takes its parent’s filename:

cadenya.yaml
.cadenya/
  toolSets/
    sandbox.yaml          # the Bare tool set
    sandbox/
      run-code.yaml       # the run_code tool
  agents/
    code-runner.yaml      # the agent
    code-runner/
      default.yaml        # its variation: prompt, model, tools

The bundle key in cadenya.yaml marks every resource the CLI writes, and it’s how the CLI knows which ones it owns:

bundleKey: code-runner

The tool set, in .cadenya/toolSets/sandbox.yaml:

metadata:
  name: Sandbox
spec:
  description: Runs Python in an isolated sandbox through your worker
  adapter:
    type: bare
    bare: {}

The tool, in .cadenya/toolSets/sandbox/run-code.yaml. llmToolName is the name the model sees, and parameters is the JSON Schema of its arguments:

metadata:
  name: Run code
spec:
  llmToolName: run_code
  description: >-
    Run Python 3 code in an isolated sandbox and get back its stdout, stderr
    and any error. Files you write stay in the sandbox for the rest of this
    conversation. Print every value you need to see.
  parameters:
    type: object
    properties:
      code:
        type: string
        description: The complete Python 3 program to run.
    required:
      - code
    additionalProperties: false
  config:
    type: bare
    bare: {}

The agent, in .cadenya/agents/code-runner.yaml:

state: published
metadata:
  name: Code runner
spec:
  description: Answers questions about numbers and data by running Python with run_code

And its variation, in .cadenya/agents/code-runner/default.yaml. The model is a setting here, so switching models is a one-line change:

metadata:
  name: Default
spec:
  systemPromptTemplate: |
    You answer questions about numbers and data. Never compute a result in
    your head: write a short Python 3 program, run it with the run_code tool,
    and read its output. If the code fails, fix it and run it again. Then
    answer in one or two sentences with the exact numbers the code printed.
  modelConfig:
    modelId: getting-started-key.xingchen-xing4-0-29b-a4b-free
    temperature: 0
  constraints:
    maxToolCalls: 8
  assignments:
    - type: toolId
      toolId: external_id:sandbox/run-code

Any model that cadenya models list shows and that supports tool calls works in modelId. The CLI reads CADENYA_API_KEY and CADENYA_WORKSPACE_ID from the environment. Plan first, then apply:

cadenya config plan
cadenya config apply

Plan prints every create, update and delete before apply writes anything. The cadenya-config-loader GitHub Action runs the same plan or apply from a workflow, as Config files explains.

A worker that answers run_code

The worker needs the TypeScript SDK. It reaches Cloudflare with plain fetch, so it needs no Cloudflare package:

npm install @cadenya/cadenya

The worker talks to the sandbox through one small interface, so it stays the same on E2B, Daytona and Blaxel. In src/sandboxes/types.ts, with cloudflare added to the providers:

export interface RunResult {
  stdout: string;
  stderr: string;
  // Set when the code raised an exception or exited with a non-zero code.
  error?: string;
}

export interface CodeSandbox {
  readonly provider: "e2b" | "daytona" | "blaxel" | "cloudflare";
  readonly id: string;
  runPython(code: string): Promise<RunResult>;
  kill(): Promise<void>;
}

The worker streams one objective’s events and answers each run_code call. In src/worker.ts:

import type Cadenya from "@cadenya/cadenya";
import type { CodeSandbox, RunResult } from "./sandboxes/types.js";

// Watches one objective and answers every run_code call in a sandbox. The
// sandbox is created on the first call, reused for the next ones, and killed
// when the agent's turn ends. Returns the agent's last message.
export async function serveRunCode(
  client: Cadenya,
  objectiveId: string,
  createSandbox: () => Promise<CodeSandbox>,
): Promise<string> {
  let sandbox: CodeSandbox | undefined;
  let answer = "";
  try {
    const stream = await client.objectives.streamEvents(objectiveId);
    for await (const event of stream) {
      const data = event.data;

      if (data.type === "toolCalled" && data.toolCalled.llmToolName === "run_code") {
        const call = data.toolCalled;
        const code = call.arguments?.code;
        let result: RunResult;
        if (typeof code !== "string" || code.trim() === "") {
          result = { stdout: "", stderr: "", error: "run_code needs a non-empty code string" };
        } else {
          try {
            sandbox ??= await createSandbox();
            result = await sandbox.runPython(code);
          } catch (error) {
            // The agent reads the failure and can try again.
            result = { stdout: "", stderr: "", error: `sandbox error: ${(error as Error).message}` };
          }
        }
        // Long output is cut so one noisy program can't fill the context window.
        await client.objectives.setToolCallContent(objectiveId, call.toolCallId, {
          content: [{ type: "text", text: { text: JSON.stringify(result).slice(0, 8_000) } }],
        });
      }

      if (data.type === "assistantMessage" && data.assistantMessage.content) {
        answer = data.assistantMessage.content;
      }
      // The turn is over when the objective waits for the user, or ends.
      if (data.type === "stateChanged" && data.stateChanged.toState === "OBJECTIVE_STATE_WAITING") break;
      if (data.type === "finalized") break;
      if (data.type === "error" || data.type === "cancelled" || data.type === "timedOut") {
        throw new Error(`objective stopped: ${JSON.stringify(data)}`);
      }
    }
  } finally {
    await sandbox?.kill();
  }
  return answer;
}

A failed sandbox call goes back to the agent as an error it can read, so one bad program doesn’t end the objective. And the SDK’s stream reconnects on its own after a dropped connection, starting from the last event it received.

Two other ways to get the same calls fit a worker that serves many objectives:

  1. Polling. List an objective’s tool calls with executionStatus set to TOOL_CALL_EXECUTION_STATUS_WAITING_FOR_CONTENT, which returns the Bare calls still waiting for a result.
  2. Webhooks. Cadenya sends objective_event.tool_called to the agent’s webhook URL for every call, with the tool, its config and the parsed arguments.

The Cloudflare sandbox: a Worker and a Durable Object

The sandbox side is a small Worker project, sandbox-runner/, built from Cloudflare’s “Run a Linux command” and “Run Python code” pages. Docker must be running when you deploy, because Wrangler builds the image. The image comes straight from “Run Python code,” in sandbox-runner/Dockerfile:

FROM python:3.13-slim

RUN pip install --no-cache-dir numpy pandas matplotlib

WORKDIR /workspace

CMD ["sleep", "infinity"]

Packages installed in the image work with no internet access in the sandbox. The Wrangler config binds a Durable Object class to the container and names the secret the Worker needs. In sandbox-runner/wrangler.jsonc:

{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "sandbox-runner",
  "main": "src/index.ts",
  // Set this to today's date
  "compatibility_date": "2026-11-11",
  "observability": { "enabled": true },
  "containers": [
    {
      "class_name": "PythonSandbox",
      "scheduling_policy": "durable_object",
      "images": { "python": { "dockerfile": "./Dockerfile" } },
    },
  ],
  "durable_objects": {
    "bindings": [{ "class_name": "PythonSandbox", "name": "PYTHON_SANDBOX" }],
  },
  "exports": {
    "PythonSandbox": { "type": "durable-object", "storage": "sqlite" },
  },
  "secrets": { "required": ["RUN_CODE_TOKEN"] },
}

The Durable Object starts the container on the first call and runs each program as a new python3 process. The Worker checks the token in constant time, as Cloudflare’s timingSafeEqual example does, and routes each call to the sandbox with that name. In sandbox-runner/src/index.ts:

import { DurableObject } from "cloudflare:workers";

const INACTIVITY_TIMEOUT_MS = 10 * 60 * 1000;

export class PythonSandbox extends DurableObject<Env> {
  constructor(ctx: DurableObjectState, env: Env) {
    super(ctx, env);
    const container = ctx.container;
    // A restarted Durable Object sets the timeout again.
    if (container?.running) {
      void ctx.blockConcurrencyWhile(() => container.setInactivityTimeout(INACTIVITY_TIMEOUT_MS));
    }
  }

  async runPython(code: string) {
    const container = this.ctx.container;
    if (!container) throw new Error("No container is configured");

    if (!container.running) {
      container.start({
        image: container.images.python,
        // Block the code from reaching the Internet
        enableInternet: false,
      });
      await container.setInactivityTimeout(INACTIVITY_TIMEOUT_MS);
    }

    // Each run is a new Python process, so variables do not carry over
    const process = await container.exec(["timeout", "--kill-after=5", "60", "python3", "-"], {
      stdin: new Response(code).body!,
      // Files that the code writes here stay until the instance stops
      cwd: "/workspace",
    });
    const output = await process.output();
    const decoder = new TextDecoder();
    return {
      stdout: decoder.decode(output.stdout),
      stderr: decoder.decode(output.stderr),
      // 124 or 137 if the code timed out, 1 if it raised an exception
      exitCode: output.exitCode,
    };
  }

  async kill() {
    if (this.ctx.container?.running) await this.ctx.container.destroy();
  }
}

function authorized(request: Request, env: Env): boolean {
  const encoder = new TextEncoder();
  const given = encoder.encode(request.headers.get("Authorization") ?? "");
  const expected = encoder.encode(`Bearer ${env.RUN_CODE_TOKEN}`);
  // Compare in constant time, even when the lengths differ.
  return given.byteLength === expected.byteLength
    ? crypto.subtle.timingSafeEqual(given, expected)
    : !crypto.subtle.timingSafeEqual(given, given);
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    if (!authorized(request, env)) return new Response("Unauthorized", { status: 401 });

    const url = new URL(request.url);
    const match = /^\/sandboxes\/([a-z0-9][a-z0-9-]{0,62})\/(python|kill)$/.exec(url.pathname);
    if (!match || request.method !== "POST") return new Response("Not found", { status: 404 });

    const sandbox = env.PYTHON_SANDBOX.getByName(match[1]);
    if (match[2] === "kill") {
      await sandbox.kill();
      return new Response(null, { status: 204 });
    }
    return Response.json(await sandbox.runPython(await request.text()));
  },
} satisfies ExportedHandler<Env>;

Put a long random token in sandbox-runner/.dev.vars as RUN_CODE_TOKEN="...", then generate types and deploy:

npx wrangler types
npx wrangler deploy --secrets-file .dev.vars

On your machine, the Cadenya worker calls that Worker. In src/sandboxes/cloudflare.ts:

import type { CodeSandbox } from "./types.js";

// Reads CLOUDFLARE_SANDBOX_URL (your workers.dev URL) and RUN_CODE_TOKEN.
export async function createCloudflareSandbox(name: string): Promise<CodeSandbox> {
  const base = process.env.CLOUDFLARE_SANDBOX_URL;
  const token = process.env.RUN_CODE_TOKEN;
  if (!base || !token) throw new Error("Set CLOUDFLARE_SANDBOX_URL and RUN_CODE_TOKEN");

  async function post(action: "python" | "kill", body?: string): Promise<Response> {
    const res = await fetch(`${base}/sandboxes/${name}/${action}`, {
      method: "POST",
      headers: { Authorization: `Bearer ${token}` },
      body,
    });
    if (!res.ok) throw new Error(`sandbox-runner returned ${res.status}`);
    return res;
  }

  return {
    provider: "cloudflare",
    id: name,
    async runPython(code) {
      const out = (await (await post("python", code)).json()) as {
        stdout: string;
        stderr: string;
        exitCode: number;
      };
      return {
        stdout: out.stdout,
        stderr: out.stderr,
        error: out.exitCode === 0 ? undefined : `exit code ${out.exitCode}`,
      };
    },
    async kill() {
      await post("kill");
    },
  };
}

A few things to know about the Cloudflare side:

  1. exec() waits for a container that’s still starting, and it has no timeout of its own, so the program runs under GNU timeout.
  2. Each call starts a new Python process, so variables don’t carry over between calls. Files in /workspace do, because the instance stays the same.
  3. The sandbox name is the security boundary. Cloudflare’s docs say to “give each user their own sandbox name, and authenticate callers first,” and here every objective gets its own name.
  4. destroy() stops the instance at once. The 10 minute inactivity timeout stops a container that a crashed worker left behind.

Run it

The script that starts an objective picks the runner from SANDBOX_PROVIDER. In src/run.ts:

import Cadenya from "@cadenya/cadenya";
import { createSandbox, providerFromEnv } from "./sandboxes/index.js";
import { serveRunCode } from "./worker.js";

const client = new Cadenya(); // reads CADENYA_API_KEY and CADENYA_WORKSPACE_ID
const provider = providerFromEnv(); // e2b, daytona, blaxel or cloudflare

const objective = await client.objectives.create({
  agentId: "external_id:code-runner",
  firstUserMessage: "What is the 1,000th prime number, and what is the sum of the first 1,000 primes?",
});
const id = objective.metadata.id;

const answer = await serveRunCode(client, id, () =>
  createSandbox(provider, { objective: id }, `run-code-${id.slice(-12).toLowerCase()}`),
);
console.log(answer);

createSandbox in src/sandboxes/index.ts calls createCloudflareSandbox(name) when SANDBOX_PROVIDER is cloudflare. The name, such as run-code- and the objective ID’s last 12 characters, fits the Worker’s route. Set CLOUDFLARE_SANDBOX_URL and RUN_CODE_TOKEN, then run it:

SANDBOX_PROVIDER=cloudflare npx tsx src/run.ts

You should see the agent’s answer in one or two sentences. The agent, the prompt and the worker are the same as in the E2B guide, where a run on October 29, 2026 answered:

The 1,000th prime number is **7919**, and the sum of the first 1,000 primes is **3,682,913**.

The worker sends each result back in the same shape, {"stdout":"...","stderr":""}, with an error field when the exit code isn’t 0. The python:3.13-slim image runs Python 3.13.

Ask a person before the code runs

Set requiresApproval: true on the tool, and the loop parks on every run_code call until someone approves or denies it:

spec:
  llmToolName: run_code
  requiresApproval: true

The objective then writes a toolApprovalRequested event with the model’s arguments, which here are the code itself. Approve the call, and the toolCalled event reaches your worker:

cadenya objectives approve-tool-call <objective-id> <tool-call-id>

Or deny it with a memo that steers the agent:

cadenya objectives deny-tool-call <objective-id> <tool-call-id> \
  --memo "Don't open network connections. Read the CSV from /tmp instead."

The worker doesn’t change. It only ever sees calls that a person approved.

The HTTP tool set variant: the agent calls your Worker directly

Your Cloudflare Worker already has a public URL, so an HTTP tool set can send each call straight to it, with no worker on your side. Tool set requests go only to hosts on the account’s trusted endpoints list, so add yours first:

cadenya trusted-endpoints create --name sandbox-runner --host sandbox-runner.<your-subdomain>.workers.dev

The tool set sets the base URL and a header that reads a tool set secret, so the token never appears in the prompt or in your repository:

metadata:
  name: Sandbox runner
spec:
  description: Runs Python in an isolated sandbox behind your own run-code endpoint
  adapter:
    type: http
    http:
      baseUrl: https://sandbox-runner.<your-subdomain>.workers.dev
      headers:
        Authorization: "Bearer {{ secrets.RUN_CODE_TOKEN }}"

The tool keeps the same llmToolName and parameters as the Bare one, with an HTTP config instead. requestBodyTemplate builds the POST body, and {{ arguments | json }} sends the tool’s arguments as JSON:

  config:
    type: http
    http:
      requestMethod: POST
      path: /run-code
      requestBodyContentType: application/json
      requestBodyTemplate: "{{ arguments | json }}"

Apply both, then store the same token as a tool set secret. It’s encrypted at rest and decrypted only when a call uses it:

cadenya config apply
cadenya tool-sets secrets create <tool-set-id> --name RUN_CODE_TOKEN --value "$RUN_CODE_TOKEN"

Every call carries an X-Cadenya-Objective-Id header, so the Worker can keep one sandbox per objective. Add this route to the fetch handler in sandbox-runner/src/index.ts, right after the line that parses url:

    if (url.pathname === "/run-code" && request.method === "POST") {
      const objective = request.headers.get("X-Cadenya-Objective-Id");
      if (!objective) return Response.json({ error: "missing X-Cadenya-Objective-Id" }, { status: 400 });

      let code: unknown;
      try {
        code = ((await request.json()) as { code?: unknown }).code;
      } catch {
        return Response.json({ error: "the body must be JSON" }, { status: 400 });
      }
      if (typeof code !== "string" || code.trim() === "") {
        return Response.json({ error: "code must be a non-empty string" }, { status: 400 });
      }
      // One sandbox per objective, so files stay between calls.
      const sandbox = env.PYTHON_SANDBOX.getByName(`objective-${objective.toLowerCase()}`);
      return Response.json(await sandbox.runPython(code));
    }

Each objective’s container keeps its files between calls and stops 10 minutes after the last one, through the same inactivity timeout.

What does Cadenya add to a Cloudflare sandbox?

A sandbox runs the code it’s handed. Cloudflare’s docs say so: “A sandbox is an isolated place to run code.” Cadenya is the agent loop around it, hosted, and the sandbox joins it as one tool set. Here’s what that covers:

  1. The agent loop, with nothing to write or host. Cadenya calls the model, records each tool call, waits for your worker’s result, and calls the model again until the turn is done.
  2. A durable record of every run. Each objective keeps an event log of its loop, with every tool call and its result. List it after a run or stream it while the agent works.
  3. A person approves the code before it runs. requiresApproval parks the loop on toolApprovalRequested, and a denial carries a memo that steers the agent.
  4. Conversations that continue. A Continue message picks a waiting objective back up with the whole conversation, and the sandbox name still points at the same Durable Object.
  5. Your own API next to the sandbox. Point a tool set at your OpenAPI 3 spec, and every operation becomes a tool. Bare, HTTP and MCP tool sets plug in the same way, and any tool can require approval.
  6. Secrets that stay out of the prompt. Tool set secrets use envelope encryption with a unique data key for each value, and Cadenya decrypts them only at the point of use.
  7. Any model, set per variation. The model is a setting on a variation, so a model swap needs no deploy, and weighted selection favors the variations that score well.
  8. The whole setup as files. The agent, its variation and its tools live in .cadenya/, and cadenya config apply or the GitHub Action applies them. SDKs cover TypeScript, Python, Ruby and Go, all at 1.9.0.
  9. A price in one line. Free for 1,000 loops a month, $49 a month for 50,000, then $0.0015 a loop. A loop is one LLM request.

The tool sets guide shows Bare and HTTP tool sets in the app, and the free plan needs no card.

No account yet? A coding agent can create a temporary workspace with cadenya workspaces create --temporary, run its first objectives there, and hand you a link to claim it, as auth.md explains. To create an account, sign up at app.cadenya.com/signup, then copy your API key from the API keys page at app.cadenya.com/account/apiKeys.

Grow wherever AI goes next.

Start shipping agents that are equipped to evolve.

A pine bonsai overlooking a mountain lake