Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Sim runs an app, a realtime server, PostgreSQL, Redis, and a scheduler. This pag

The Next.js app serves the workflow builder, API routes, and workflow orchestration. Local JavaScript runs in Node child workers using isolated-vm inside the app container. The app and those workers share the container's memory budget. The Helm chart requests 4 GiB and limits the app to 8 GiB; `docker-compose.prod.yml` sets an 8 GB memory limit without a reservation.

E2B or Daytona moves supported code execution to a remote sandbox. `TRIGGER_DEV_ENABLED` routes asynchronous jobs to Trigger.dev; the default deployment uses database-backed jobs. See [Sandboxes](/platform/self-hosting/sandboxes) for the provider and image requirements.
E2B, Daytona, or boxd moves supported code execution to a remote sandbox. `TRIGGER_DEV_ENABLED` routes asynchronous jobs to Trigger.dev; the default deployment uses database-backed jobs. See [Sandboxes](/platform/self-hosting/sandboxes) for the provider and image requirements.

Any replica can serve files once shared object storage is configured. Before adding replicas, configure storage, Redis, and database connection capacity as described in [Scaling and high availability](/platform/self-hosting/scaling).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,16 @@ Who may sign up and sign in — the allowlists, blocklists, `DISABLE_REGISTRATIO

| Variable | Description |
|----------|-------------|
| `SANDBOX_PROVIDER` | Remote sandbox provider: `e2b` (default) or `daytona` |
| `SANDBOX_PROVIDER` | Remote sandbox provider: `e2b` (default), `daytona`, or `boxd` |
| `E2B_ENABLED` / `E2B_API_KEY` | Enable E2B remote execution |
| `DAYTONA_API_KEY` | Daytona API key (used when `SANDBOX_PROVIDER=daytona`) |
| `E2B_FUNCTION_TEMPLATE_ID` | Immutable `<template>:<build-id>` ref for the Function base image. Required for E2B; a mutable tag is refused |
| `E2B_FUNCTION_TEMPLATE_GENERATION` | Monotonic release generation printed by the same build. Required for E2B |
| `DAYTONA_FUNCTION_SNAPSHOT_ID` | Immutable snapshot **ID** (not a name) for the Function base image. Required for Daytona |
| `E2B_PI_TEMPLATE_ID` / `DAYTONA_PI_SNAPSHOT_ID` | The image Pi runs on. Separate from the Function base — configuring the provider and Function image alone leaves Pi failing closed |
| `BOXD_API_KEY` | boxd API key (used when `SANDBOX_PROVIDER=boxd`) |
| `BOXD_REGION` / `BOXD_ORG` | Region and org for boxd sandboxes. The region must hold the snapshots; the org defaults to the key's |
| `BOXD_FUNCTION_SNAPSHOT` | Version-pinned `<snapshot>@<version>` ref for the Function base image. Required for boxd; an unpinned name is refused |
| `E2B_PI_TEMPLATE_ID` / `DAYTONA_PI_SNAPSHOT_ID` / `BOXD_PI_SNAPSHOT` | The image Pi runs on. Separate from the Function base — configuring the provider and Function image alone leaves Pi failing closed |
| `SANDBOXES_ENABLED` / `NEXT_PUBLIC_SANDBOXES_ENABLED` | Enable custom sandbox entitlement through deployment configuration where supported; see the [enterprise guide](/platform/enterprise/self-hosted) for billing-mode requirements. Neither is sufficient on its own — a provider key **and** an immutable Function base must also be configured. Set the `NEXT_PUBLIC_` twin only after the server side works; it enables nothing by itself — it reveals the Function block's Sandbox selector, and on a Compose install or source checkout `bunx sim-setup doctor` confirms it agrees with the selected provider's readiness |
| `IVM_MAX_EXECUTIONS_PER_WORKER` | Executions before an isolated-vm worker is recycled |
| `IVM_MAX_BROKERS_PER_EXECUTION` | Host-call brokers per execution |
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/platform/self-hosting/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The editor and execution engine run within your deployment. Configure these depe
| Agent blocks | A model provider key or a self-hosted compatible endpoint such as Ollama, vLLM, LM Studio, or LiteLLM. |
| Chat | `COPILOT_API_KEY` for the default Sim service. Set `NEXT_PUBLIC_CHAT_DISABLED=true` to hide Chat when it is not configured. |
| OAuth integrations | Your provider app and credentials for each OAuth service you use. API-key integrations take keys in their blocks. |
| Remote Function or Pi execution | An E2B or Daytona provider key and the appropriate immutable image. Function and Pi use separate images. |
| Remote Function or Pi execution | An E2B, Daytona, or boxd provider key and the appropriate immutable image. Function and Pi use separate images. |

Plain JavaScript without `import` or `require` runs in isolated-vm within Node child workers in the app container. Python, Shell, imported JavaScript, custom Function Sandboxes, and file-path or sandbox execution require remote sandbox configuration. See [Sandboxes](/platform/self-hosting/sandboxes).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The chart bundles PostgreSQL and Redis for evaluation. For production, decide ho
| Ingress | Off | You install the controller; the chart renders the Ingress |
| TLS certificates | Off | You provision them |
| Remote sandbox | Off | Required for Python, Shell, and imported JavaScript — a provider **and** an immutable Function image. See [Sandboxes](/platform/self-hosting/sandboxes) |
| Pi execution | Off | A separate image from the Function one, set with `E2B_PI_TEMPLATE_ID` (a template name, an alias, or an immutable `<template>:<build-id>` ref) or `DAYTONA_PI_SNAPSHOT_ID`. Unlike the Function base these are not format-validated, but execution still fails closed when unset |
| Pi execution | Off | A separate image from the Function one, set with `E2B_PI_TEMPLATE_ID` (a template name, an alias, or an immutable `<template>:<build-id>` ref) `DAYTONA_PI_SNAPSHOT_ID`, or `BOXD_PI_SNAPSHOT`. Unlike the Function base these are not format-validated, but execution still fails closed when unset |
| PII redaction, Ollama, telemetry collector | Off | Optional, off unless you enable them |

The bundled Postgres uses a 10 Gi `ReadWriteOnce` volume and is intended for evaluation. Moving to managed Postgres is the single most important production change.
Expand Down
47 changes: 43 additions & 4 deletions apps/docs/content/docs/platform/self-hosting/sandboxes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Selecting a sandbox without a configured provider is refused with 503. File-path

Run these repository scripts from a checkout with dependencies installed (`bun install` at the repository root). Supply provider credentials to the build environment. Custom workspace sandboxes layer their packages on this base.

<Tabs items={['E2B', 'Daytona']}>
<Tabs items={['E2B', 'Daytona', 'boxd']}>
<Tab value="E2B">

```bash
Expand Down Expand Up @@ -70,20 +70,46 @@ SANDBOX_PARITY_MANIFEST_BASELINE=/tmp/function-sandbox-manifest.json \
bun run apps/sim/scripts/verify-sandbox-parity.ts
```

Replace the placeholders before running.

</Tab>
<Tab value="boxd">

[boxd](https://boxd.sh?ref=sim) runs each sandbox as an isolated microVM restored from a snapshot. Like Daytona, the builder reconstructs packages from an accepted E2B manifest, so complete the E2B build and verification first. It boots a build machine in the region you pick, installs the Function surface, saves the snapshot, and deletes the build machine. Snapshots stay in their region, so build in the region you will run in.

```bash
BOXD_API_KEY=... \
BOXD_REGION=nyc \
bun run apps/sim/scripts/build-function-boxd-snapshot.ts \
--name "sim-function-<release>" \
--parity-manifest /tmp/function-sandbox-manifest.json
```

The builder prints a version-pinned `<snapshot-id>@<version>` reference. Verify it against the accepted E2B baseline:

```bash
SANDBOX_PROVIDER=boxd \
BOXD_API_KEY=... \
BOXD_REGION=nyc \
BOXD_FUNCTION_SNAPSHOT='<snapshot>@<version>' \
SANDBOX_PARITY_MANIFEST_BASELINE=/tmp/function-sandbox-manifest.json \
bun run apps/sim/scripts/verify-sandbox-parity.ts
```

Replace the placeholders before running.

</Tab>
</Tabs>

<Callout type="warn">
Function images must be immutable. `E2B_FUNCTION_TEMPLATE_ID` requires an exact `<template>:<build-id>` reference with a UUID build ID, plus the positive `E2B_FUNCTION_TEMPLATE_GENERATION` printed by that build. `DAYTONA_FUNCTION_SNAPSHOT_ID` requires a snapshot UUID, not a mutable name. Missing or invalid values do not fall back to a shell image.
Function images must be immutable. `E2B_FUNCTION_TEMPLATE_ID` requires an exact `<template>:<build-id>` reference with a UUID build ID, plus the positive `E2B_FUNCTION_TEMPLATE_GENERATION` printed by that build. `DAYTONA_FUNCTION_SNAPSHOT_ID` requires a snapshot UUID, not a mutable name. `BOXD_FUNCTION_SNAPSHOT` requires a `<snapshot>@<version>` pin: re-saving a boxd snapshot under the same name creates a new version, and Sim refuses to run on a machine restored from any other version. Missing or invalid values do not fall back to a shell image.
</Callout>

## Configure the deployment

Apply the verified runtime values through the deployment's environment or secret mechanism:

<Tabs items={['E2B', 'Daytona']}>
<Tabs items={['E2B', 'Daytona', 'boxd']}>
<Tab value="E2B">

```dotenv
Expand All @@ -101,6 +127,16 @@ E2B_FUNCTION_TEMPLATE_GENERATION=<release-epoch-ms>
SANDBOX_PROVIDER=daytona
DAYTONA_API_KEY=...
DAYTONA_FUNCTION_SNAPSHOT_ID=<snapshot-uuid>
```

</Tab>
<Tab value="boxd">

```dotenv
SANDBOX_PROVIDER=boxd
BOXD_API_KEY=...
BOXD_REGION=<region-of-the-snapshot>
BOXD_FUNCTION_SNAPSHOT=<snapshot>@<version>
```

</Tab>
Expand Down Expand Up @@ -135,9 +171,12 @@ MOTHERSHIP_E2B_TEMPLATE_ID=<shell-template-ref>

# Daytona shell image
DAYTONA_SHELL_SNAPSHOT_ID=<shell-snapshot-ref>

# boxd shell snapshot
BOXD_SHELL_SNAPSHOT=<shell-snapshot>
```

These values do not replace `E2B_FUNCTION_TEMPLATE_ID` or `DAYTONA_FUNCTION_SNAPSHOT_ID`. Shell, Function, document, and Pi images have separate package contracts and release cadences. Pi also needs `E2B_PI_TEMPLATE_ID` or `DAYTONA_PI_SNAPSHOT_ID`; revealing a Pi mode with `NEXT_PUBLIC_E2B_ENABLED` does not supply that image.
These values do not replace `E2B_FUNCTION_TEMPLATE_ID`, `DAYTONA_FUNCTION_SNAPSHOT_ID`, or `BOXD_FUNCTION_SNAPSHOT`. Shell, Function, document, and Pi images have separate package contracts and release cadences. Pi also needs `E2B_PI_TEMPLATE_ID`, `DAYTONA_PI_SNAPSHOT_ID`, or `BOXD_PI_SNAPSHOT`; revealing a Pi mode with `NEXT_PUBLIC_E2B_ENABLED` does not supply that image.

## Related docs

Expand Down
2 changes: 2 additions & 0 deletions apps/docs/content/docs/platform/self-hosting/security.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Workflows can execute user-authored JavaScript and Python. Know which sandbox yo
| **isolated-vm** (default) | none | V8 isolate in a Node child worker inside the app container. The worker shares the container's network namespace and OS/filesystem context. JavaScript only. |
| **E2B** | `E2B_ENABLED=true`, `E2B_API_KEY`, `E2B_FUNCTION_TEMPLATE_ID`, `E2B_FUNCTION_TEMPLATE_GENERATION` | Remote sandbox per execution; requires outbound access to E2B. Review the provider's isolation and network configuration. |
| **Daytona** | `SANDBOX_PROVIDER=daytona`, `DAYTONA_API_KEY`, `DAYTONA_FUNCTION_SNAPSHOT_ID` | Remote sandbox per execution. |
| **boxd** | `SANDBOX_PROVIDER=boxd`, `BOXD_API_KEY`, `BOXD_FUNCTION_SNAPSHOT` | Remote microVM per execution, created isolated: no access to the org's other machines and no metadata endpoint. |

Python, Shell, JavaScript with external imports, and tooling-dependent blocks
require a remote sandbox provider. On a billing-free self-host the provider and
Expand All @@ -193,6 +194,7 @@ continues to run in the local isolate when no remote provider is configured.
- `E2B_FUNCTION_TEMPLATE_ID` must be `<template>:<build-id>`, where the build id is a UUID. A human-readable tag is rejected because E2B lets tags be reassigned.
- `E2B_FUNCTION_TEMPLATE_GENERATION` must be a positive integer release generation.
- `DAYTONA_FUNCTION_SNAPSHOT_ID` must be the snapshot **ID** (a UUID), not the snapshot name — Daytona accepts a name anywhere it accepts an ID, and only the ID is immutable.
- `BOXD_FUNCTION_SNAPSHOT` must pin a version, `<snapshot>@<version>`. boxd keeps only the latest version of a snapshot name, so Sim checks the version the machine was restored from and refuses any other.

Without valid provider credentials and the required Function image, code that needs a remote sandbox fails with a configuration error. Verify readiness before enabling its browser controls.
</Callout>
Expand Down
6 changes: 3 additions & 3 deletions apps/docs/content/docs/workflows/blocks/function.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ on a self-hosted instance, build and configure the provider's dedicated
[Function base](/platform/enterprise/self-hosted) first. Python can return plots as images; you can also write image files under `/tmp/sim/outputs`.

If no remote provider is configured, JavaScript without `import` or `require`
continues to run in Sim's local isolated VM. Missing E2B or Daytona configuration
continues to run in Sim's local isolated VM. Missing E2B, Daytona, or boxd configuration
does not disable that path. Remote-only code fails with an explicit configuration
error; Sim does not reinterpret Python or Shell as JavaScript.

The dedicated Function base has the same runtime and universal package contract
on E2B and Daytona. It includes this data-science stack; use a workspace sandbox
on E2B, Daytona, and boxd. It includes this data-science stack; use a workspace sandbox
when another dependency must be present:

- **Data and graphs:** `pandas`, `numpy`, `scipy`, `xarray`, `numba`, `networkx`
Expand Down Expand Up @@ -272,7 +272,7 @@ open the three-dot menu at the end of the failed status row and choose **Retry
build**. Save or discard unsaved sandbox edits first so the retry always uses the
visible spec.

On a self-hosted deployment using Daytona, dependencies, system packages, and
On a self-hosted deployment using Daytona or boxd, dependencies, system packages, and
managed CLI tools install inside the sandbox at the start of every run instead,
adding startup time per execution. Prebuilt images require E2B.

Expand Down
8 changes: 8 additions & 0 deletions apps/sim/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ NEXT_PUBLIC_APP_URL=http://localhost:3000
# DAYTONA_API_KEY=
# DAYTONA_FUNCTION_SNAPSHOT_ID=<snapshot-uuid> # Copy the immutable ID printed by the Daytona builder
# DAYTONA_SHELL_SNAPSHOT_ID= # Mothership shell snapshot ref, required when Mothership runs code on Daytona
#
# boxd
# Build from an accepted E2B parity manifest with: bun run apps/sim/scripts/build-function-boxd-snapshot.ts --name <name> --parity-manifest <path>
# SANDBOX_PROVIDER=boxd
# BOXD_API_KEY=
# BOXD_REGION=nyc # Region of the snapshots ('fra' or 'nyc')
# BOXD_FUNCTION_SNAPSHOT=<snapshot>@<version> # Copy the version-pinned ref printed by the boxd builder
# BOXD_SHELL_SNAPSHOT= # Mothership shell snapshot ref, required when Mothership runs code on boxd

# Security (Required)
ENCRYPTION_KEY=your_encryption_key # Use `openssl rand -hex 32` to generate, used to encrypt environment variables and connected-account OAuth tokens (ENCRYPT_ACCOUNT_TOKENS=false opts the tokens out)
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/lib/billing/sandbox-pricing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('sandbox pricing', () => {
it.each([
['e2b', 0.1656],
['daytona', 0.16668],
['boxd', 0.20696],
] as const)('prices one hour of the Function profile on %s', (provider, expected) => {
const pricing = createSandboxPricing(provider, 'code', 1)

Expand All @@ -31,6 +32,7 @@ describe('sandbox pricing', () => {
it.each([
['e2b', 0.3312],
['daytona', 0.33228],
['boxd', 0.41296],
] as const)(
'prices one hour of the Pi sandbox on %s at its build resources',
(provider, expected) => {
Expand Down
23 changes: 23 additions & 0 deletions apps/sim/lib/billing/sandbox-pricing.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { getCostMultiplier } from '@/lib/core/config/env-flags'
import {
FUNCTION_BOXD_DISK_GB,
FUNCTION_BOXD_MEMORY_GB,
FUNCTION_DAYTONA_DISK_GB,
FUNCTION_SANDBOX_CPU_COUNT,
FUNCTION_SANDBOX_MEMORY_GB,
} from '@/lib/execution/remote-sandbox/function-resources'
import {
PI_BOXD_DISK_GB,
PI_BOXD_MEMORY_GB,
PI_DAYTONA_DISK_GB,
PI_SANDBOX_CPU_COUNT,
PI_SANDBOX_MEMORY_GB,
Expand All @@ -20,6 +24,10 @@ const DAYTONA_MEMORY_USD_PER_GIB_SECOND = 0.0162 / 3600
* credits, and discounts are intentionally not subtracted.
*/
const DAYTONA_DISK_USD_PER_GIB_SECOND = 0.000108 / 3600
/** boxd list rates; Sim prices the full machine size rather than the active vCPU boxd bills. */
const BOXD_CPU_USD_PER_VCPU_SECOND = 0.047 / 3600
const BOXD_MEMORY_USD_PER_GIB_SECOND = 0.014 / 3600
const BOXD_DISK_USD_PER_GIB_SECOND = 0.000096 / 3600

export interface SandboxPricing {
provider: SandboxProviderId
Expand Down Expand Up @@ -85,6 +93,21 @@ const PRICING_BY_PROVIDER: Record<SandboxProviderId, ProviderPricing> = {
diskUsdPerGiBSecond: DAYTONA_DISK_USD_PER_GIB_SECOND,
},
},
boxd: {
resources: {
vcpu: FUNCTION_SANDBOX_CPU_COUNT,
memoryGiB: FUNCTION_BOXD_MEMORY_GB,
diskGiB: FUNCTION_BOXD_DISK_GB,
},
resourcesByKind: {
pi: { vcpu: PI_SANDBOX_CPU_COUNT, memoryGiB: PI_BOXD_MEMORY_GB, diskGiB: PI_BOXD_DISK_GB },
},
rates: {
cpuUsdPerVcpuSecond: BOXD_CPU_USD_PER_VCPU_SECOND,
memoryUsdPerGiBSecond: BOXD_MEMORY_USD_PER_GIB_SECOND,
diskUsdPerGiBSecond: BOXD_DISK_USD_PER_GIB_SECOND,
},
},
}

export function createSandboxPricing(
Expand Down
10 changes: 9 additions & 1 deletion apps/sim/lib/core/config/env-capabilities.server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('server environment capabilities', () => {
SANDBOX_PROVIDER: undefined,
DAYTONA_API_KEY: undefined,
DAYTONA_FUNCTION_SNAPSHOT_ID: undefined,
BOXD_API_KEY: undefined,
BOXD_FUNCTION_SNAPSHOT: undefined,
})
})

Expand Down Expand Up @@ -72,11 +74,17 @@ describe('server environment capabilities', () => {
expect(getSelectedSandboxProviderId()).toBe('daytona')
})

it('selects the boxd adapter without requiring a Function base', () => {
setEnv({ SANDBOX_PROVIDER: 'boxd', BOXD_API_KEY: 'boxd-key' })

expect(getSelectedSandboxProviderId()).toBe('boxd')
})

it('rejects an unknown sandbox provider during selection', () => {
setEnv({ SANDBOX_PROVIDER: 'modal' })

expect(() => getSelectedSandboxProviderId()).toThrow(
'Unknown SANDBOX_PROVIDER "modal". Expected one of: e2b, daytona'
'Unknown SANDBOX_PROVIDER "modal". Expected one of: e2b, daytona, boxd'
)
})
})
23 changes: 23 additions & 0 deletions apps/sim/lib/core/config/env-capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,29 @@ describe('env capabilities', () => {
).toThrow(/immutable Daytona snapshot ID/)
})

it('requires boxd credentials and a version-pinned Function snapshot', () => {
expect(
requireCapability(SANDBOX_CAPABILITY, {
SANDBOX_PROVIDER: 'boxd',
BOXD_API_KEY: 'boxd-key',
BOXD_FUNCTION_SNAPSHOT: 'sim-function@3',
}).providerId
).toBe('boxd')
expect(() =>
requireCapability(SANDBOX_CAPABILITY, {
SANDBOX_PROVIDER: 'boxd',
BOXD_API_KEY: 'boxd-key',
})
).toThrow(/BOXD_FUNCTION_SNAPSHOT/)
expect(() =>
requireCapability(SANDBOX_CAPABILITY, {
SANDBOX_PROVIDER: 'boxd',
BOXD_API_KEY: 'boxd-key',
BOXD_FUNCTION_SNAPSHOT: 'sim-function',
})
).toThrow(/must pin a boxd snapshot version/)
})

it('reports an unknown sandbox selector without throwing during inspection', () => {
expect(inspectCapability(SANDBOX_CAPABILITY, { SANDBOX_PROVIDER: 'unknown' })).toMatchObject({
providerId: null,
Expand Down
Loading