Skip to content

Commit 6ea6db5

Browse files
feat(sandbox): add boxd as a remote sandbox provider
Adds a boxd adapter next to E2B and Daytona. It mirrors the Daytona adapter: runtime dependency strategy, one snapshot per sandbox kind, a wall-clock lifetime, and kill() deletes the machine. Machines are created isolated. BOXD_FUNCTION_SNAPSHOT takes a version-pinned <snapshot>@<version> ref. The adapter checks the version the machine was restored from and fails closed on any other. Includes the Function snapshot builder, capability and sim-setup registration, billing rates, the conformance suite run three ways, a gated live smoke test, and self-hosting docs.
1 parent dbe0108 commit 6ea6db5

39 files changed

Lines changed: 2144 additions & 150 deletions

‎apps/docs/content/docs/platform/self-hosting/architecture.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Sim runs an app, a realtime server, PostgreSQL, Redis, and a scheduler. This pag
2525

2626
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.
2727

28-
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.
28+
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.
2929

3030
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).
3131

‎apps/docs/content/docs/platform/self-hosting/environment-variables.mdx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,16 @@ Who may sign up and sign in — the allowlists, blocklists, `REGISTRATION_MODE`,
180180

181181
| Variable | Description |
182182
|----------|-------------|
183-
| `SANDBOX_PROVIDER` | Remote sandbox provider: `e2b` (default) or `daytona` |
183+
| `SANDBOX_PROVIDER` | Remote sandbox provider: `e2b` (default), `daytona`, or `boxd` |
184184
| `E2B_ENABLED` / `E2B_API_KEY` | Enable E2B remote execution |
185185
| `DAYTONA_API_KEY` | Daytona API key (used when `SANDBOX_PROVIDER=daytona`) |
186186
| `E2B_FUNCTION_TEMPLATE_ID` | Immutable `<template>:<build-id>` ref for the Function base image. Required for E2B; a mutable tag is refused |
187187
| `E2B_FUNCTION_TEMPLATE_GENERATION` | Monotonic release generation printed by the same build. Required for E2B |
188188
| `DAYTONA_FUNCTION_SNAPSHOT_ID` | Immutable snapshot **ID** (not a name) for the Function base image. Required for Daytona |
189-
| `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 |
189+
| `BOXD_API_KEY` | boxd API key (used when `SANDBOX_PROVIDER=boxd`) |
190+
| `BOXD_REGION` / `BOXD_ORG` | Region and org for boxd sandboxes. The region must hold the snapshots; the org defaults to the key's |
191+
| `BOXD_FUNCTION_SNAPSHOT` | Version-pinned `<snapshot>@<version>` ref for the Function base image. Required for boxd; an unpinned name is refused |
192+
| `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 |
190193
| `SANDBOXES_ENABLED` | Enable custom sandbox entitlement through deployment configuration where supported; see the [enterprise guide](/platform/enterprise/self-hosted) for billing-mode requirements. Not sufficient on its own — a provider key **and** an immutable Function base must also be configured. The Function block's Sandbox selector appears once the server confirms both |
191194
| `IVM_MAX_EXECUTIONS_PER_WORKER` | Executions before an isolated-vm worker is recycled |
192195
| `IVM_MAX_BROKERS_PER_EXECUTION` | Host-call brokers per execution |

‎apps/docs/content/docs/platform/self-hosting/index.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The editor and execution engine run within your deployment. Configure these depe
6565
| Agent blocks | A model provider key or a self-hosted compatible endpoint such as Ollama, vLLM, LM Studio, or LiteLLM. |
6666
| Chat | `COPILOT_API_KEY` for the default Sim service. Set `NEXT_PUBLIC_CHAT_DISABLED=true` to hide Chat when it is not configured. |
6767
| OAuth integrations | Your provider app and credentials for each OAuth service you use. API-key integrations take keys in their blocks. |
68-
| Remote Function or Pi execution | An E2B or Daytona provider key and the appropriate immutable image. Function and Pi use separate images. |
68+
| Remote Function or Pi execution | An E2B, Daytona, or boxd provider key and the appropriate immutable image. Function and Pi use separate images. |
6969

7070
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).
7171

‎apps/docs/content/docs/platform/self-hosting/reference-architectures.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The chart bundles PostgreSQL and Redis for evaluation. For production, decide ho
2424
| Ingress | Off | You install the controller; the chart renders the Ingress |
2525
| TLS certificates | Off | You provision them |
2626
| Remote sandbox | Off | Required for Python, Shell, and imported JavaScript — a provider **and** an immutable Function image. See [Sandboxes](/platform/self-hosting/sandboxes) |
27-
| 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 |
27+
| 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 |
2828
| PII redaction, Ollama, telemetry collector | Off | Optional, off unless you enable them |
2929

3030
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.

‎apps/docs/content/docs/platform/self-hosting/sandboxes.mdx‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Selecting a sandbox without a configured provider is refused with 503. File-path
2323

2424
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.
2525

26-
<Tabs items={['E2B', 'Daytona']}>
26+
<Tabs items={['E2B', 'Daytona', 'boxd']}>
2727
<Tab value="E2B">
2828

2929
```bash
@@ -70,20 +70,46 @@ SANDBOX_PARITY_MANIFEST_BASELINE=/tmp/function-sandbox-manifest.json \
7070
bun run apps/sim/scripts/verify-sandbox-parity.ts
7171
```
7272

73+
Replace the placeholders before running.
74+
75+
</Tab>
76+
<Tab value="boxd">
77+
78+
[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.
79+
80+
```bash
81+
BOXD_API_KEY=... \
82+
BOXD_REGION=nyc \
83+
bun run apps/sim/scripts/build-function-boxd-snapshot.ts \
84+
--name "sim-function-<release>" \
85+
--parity-manifest /tmp/function-sandbox-manifest.json
86+
```
87+
88+
The builder prints a version-pinned `<snapshot-id>@<version>` reference. Verify it against the accepted E2B baseline:
89+
90+
```bash
91+
SANDBOX_PROVIDER=boxd \
92+
BOXD_API_KEY=... \
93+
BOXD_REGION=nyc \
94+
BOXD_FUNCTION_SNAPSHOT='<snapshot>@<version>' \
95+
SANDBOX_PARITY_MANIFEST_BASELINE=/tmp/function-sandbox-manifest.json \
96+
bun run apps/sim/scripts/verify-sandbox-parity.ts
97+
```
98+
7399
Replace the placeholders before running.
74100

75101
</Tab>
76102
</Tabs>
77103

78104
<Callout type="warn">
79-
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.
105+
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.
80106
</Callout>
81107

82108
## Configure the deployment
83109

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

86-
<Tabs items={['E2B', 'Daytona']}>
112+
<Tabs items={['E2B', 'Daytona', 'boxd']}>
87113
<Tab value="E2B">
88114

89115
```dotenv
@@ -101,6 +127,16 @@ E2B_FUNCTION_TEMPLATE_GENERATION=<release-epoch-ms>
101127
SANDBOX_PROVIDER=daytona
102128
DAYTONA_API_KEY=...
103129
DAYTONA_FUNCTION_SNAPSHOT_ID=<snapshot-uuid>
130+
```
131+
132+
</Tab>
133+
<Tab value="boxd">
134+
135+
```dotenv
136+
SANDBOX_PROVIDER=boxd
137+
BOXD_API_KEY=...
138+
BOXD_REGION=<region-of-the-snapshot>
139+
BOXD_FUNCTION_SNAPSHOT=<snapshot>@<version>
104140
```
105141

106142
</Tab>
@@ -132,9 +168,12 @@ MOTHERSHIP_E2B_TEMPLATE_ID=<shell-template-ref>
132168
133169
# Daytona shell image
134170
DAYTONA_SHELL_SNAPSHOT_ID=<shell-snapshot-ref>
171+
172+
# boxd shell snapshot
173+
BOXD_SHELL_SNAPSHOT=<shell-snapshot>
135174
```
136175

137-
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`; `E2B_ENABLED` reveals the Pi cloud modes but does not supply that image.
176+
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`; `E2B_ENABLED` reveals the Pi cloud modes but does not supply that image.
138177

139178
## Related docs
140179

‎apps/docs/content/docs/platform/self-hosting/security.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ Workflows can execute user-authored JavaScript and Python. Know which sandbox yo
178178
| **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. |
179179
| **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. |
180180
| **Daytona** | `SANDBOX_PROVIDER=daytona`, `DAYTONA_API_KEY`, `DAYTONA_FUNCTION_SNAPSHOT_ID` | Remote sandbox per execution. |
181+
| **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. |
181182

182183
Python, Shell, JavaScript with external imports, and tooling-dependent blocks
183184
require a remote sandbox provider and, on a billing-disabled self-host, the sandbox
@@ -191,6 +192,7 @@ no remote provider is configured.
191192
- `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.
192193
- `E2B_FUNCTION_TEMPLATE_GENERATION` must be a positive integer release generation.
193194
- `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.
195+
- `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.
194196

195197
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.
196198
</Callout>

‎apps/docs/content/docs/workflows/blocks/function.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ on a self-hosted instance, build and configure the provider's dedicated
4040
[Function base](/platform/enterprise/self-hosted) first. Python can return plots as images; you can also write image files under `/tmp/sim/outputs`.
4141

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

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

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

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

‎apps/sim/.env.example‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ NEXT_PUBLIC_APP_URL=http://localhost:3000
6161
# DAYTONA_API_KEY=
6262
# DAYTONA_FUNCTION_SNAPSHOT_ID=<snapshot-uuid> # Copy the immutable ID printed by the Daytona builder
6363
# DAYTONA_SHELL_SNAPSHOT_ID= # Mothership shell snapshot ref, required when Mothership runs code on Daytona
64+
#
65+
# boxd
66+
# Build from an accepted E2B parity manifest with: bun run apps/sim/scripts/build-function-boxd-snapshot.ts --name <name> --parity-manifest <path>
67+
# SANDBOX_PROVIDER=boxd
68+
# BOXD_API_KEY=
69+
# BOXD_REGION=nyc # Region of the snapshots ('fra' or 'nyc')
70+
# BOXD_FUNCTION_SNAPSHOT=<snapshot>@<version> # Copy the version-pinned ref printed by the boxd builder
71+
# BOXD_SHELL_SNAPSHOT= # Mothership shell snapshot ref, required when Mothership runs code on boxd
6472

6573
# Security (Required)
6674
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)

‎apps/sim/lib/billing/sandbox-pricing.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('sandbox pricing', () => {
1616
it.each([
1717
['e2b', 0.1656],
1818
['daytona', 0.16668],
19+
['boxd', 0.20696],
1920
] as const)('prices one hour of the Function profile on %s', (provider, expected) => {
2021
const pricing = createSandboxPricing(provider, 'code', 1)
2122

@@ -31,6 +32,7 @@ describe('sandbox pricing', () => {
3132
it.each([
3233
['e2b', 0.3312],
3334
['daytona', 0.33228],
35+
['boxd', 0.41296],
3436
] as const)(
3537
'prices one hour of the Pi sandbox on %s at its build resources',
3638
(provider, expected) => {

‎apps/sim/lib/billing/sandbox-pricing.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { getCostMultiplier } from '@/lib/core/config/env-flags'
22
import {
3+
FUNCTION_BOXD_DISK_GB,
4+
FUNCTION_BOXD_MEMORY_GB,
35
FUNCTION_DAYTONA_DISK_GB,
46
FUNCTION_SANDBOX_CPU_COUNT,
57
FUNCTION_SANDBOX_MEMORY_GB,
68
} from '@/lib/execution/remote-sandbox/function-resources'
79
import {
10+
PI_BOXD_DISK_GB,
11+
PI_BOXD_MEMORY_GB,
812
PI_DAYTONA_DISK_GB,
913
PI_SANDBOX_CPU_COUNT,
1014
PI_SANDBOX_MEMORY_GB,
@@ -20,6 +24,10 @@ const DAYTONA_MEMORY_USD_PER_GIB_SECOND = 0.0162 / 3600
2024
* credits, and discounts are intentionally not subtracted.
2125
*/
2226
const DAYTONA_DISK_USD_PER_GIB_SECOND = 0.000108 / 3600
27+
/** boxd list rates; Sim prices the full machine size rather than the active vCPU boxd bills. */
28+
const BOXD_CPU_USD_PER_VCPU_SECOND = 0.047 / 3600
29+
const BOXD_MEMORY_USD_PER_GIB_SECOND = 0.014 / 3600
30+
const BOXD_DISK_USD_PER_GIB_SECOND = 0.000096 / 3600
2331

2432
export interface SandboxPricing {
2533
provider: SandboxProviderId
@@ -85,6 +93,21 @@ const PRICING_BY_PROVIDER: Record<SandboxProviderId, ProviderPricing> = {
8593
diskUsdPerGiBSecond: DAYTONA_DISK_USD_PER_GIB_SECOND,
8694
},
8795
},
96+
boxd: {
97+
resources: {
98+
vcpu: FUNCTION_SANDBOX_CPU_COUNT,
99+
memoryGiB: FUNCTION_BOXD_MEMORY_GB,
100+
diskGiB: FUNCTION_BOXD_DISK_GB,
101+
},
102+
resourcesByKind: {
103+
pi: { vcpu: PI_SANDBOX_CPU_COUNT, memoryGiB: PI_BOXD_MEMORY_GB, diskGiB: PI_BOXD_DISK_GB },
104+
},
105+
rates: {
106+
cpuUsdPerVcpuSecond: BOXD_CPU_USD_PER_VCPU_SECOND,
107+
memoryUsdPerGiBSecond: BOXD_MEMORY_USD_PER_GIB_SECOND,
108+
diskUsdPerGiBSecond: BOXD_DISK_USD_PER_GIB_SECOND,
109+
},
110+
},
88111
}
89112

90113
export function createSandboxPricing(

0 commit comments

Comments
 (0)