Skip to content
Merged
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
25 changes: 25 additions & 0 deletions .github/workflows/helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
# The image inventory is generated from the chart and checked here, so a
# change to its generator has to run this workflow too.
- 'scripts/generate-image-manifest.ts'
- 'scripts/write-chart-sandbox-images.ts'
- 'package.json'
pull_request:
branches: [main, staging, dev]
Expand All @@ -22,6 +23,7 @@ on:
# The image inventory is generated from the chart and checked here, so a
# change to its generator has to run this workflow too.
- 'scripts/generate-image-manifest.ts'
- 'scripts/write-chart-sandbox-images.ts'
- 'package.json'

# Pull requests cancel a superseded run; pushes never do, so a newer push cannot cut off a chart
Expand Down Expand Up @@ -341,6 +343,16 @@ jobs:
APP_VERSION: ${{ needs.release-version.outputs.version }}
run: bun run scripts/sync-chart-appversion.ts --version "${APP_VERSION}"

# The published chart pre-pulls the Function sandbox image its appVersion runs,
# read from the release tag; the file is gitignored, so only published charts
# carry it. --verify renders the chart and checks the DaemonSet holds that image.
- name: Bundle the release's sandbox Function image
env:
APP_VERSION: ${{ needs.release-version.outputs.version }}
# The script fetches the tag itself, and reads HEAD when this is the release commit
# whose tag the release job has not cut yet.
run: bun run scripts/write-chart-sandbox-images.ts --version "${APP_VERSION}" --verify

- name: Package chart
id: package
run: |
Expand Down Expand Up @@ -537,6 +549,19 @@ jobs:
APP_VERSION: ${{ needs.release-version.outputs.version }}
run: bun run scripts/sync-chart-appversion.ts --version "${APP_VERSION}"

- name: Set up Helm
if: steps.pages.outputs.exists == 'true'
uses: azure/setup-helm@2f5e7bc67f1f9972ab16657bb795f36d8f04de0e # v5.1.0
with:
version: v3.16.4

# Same bundled sandbox image as the OCI publish, so both repos ship the same chart.
- name: Bundle the release's sandbox Function image
if: steps.pages.outputs.exists == 'true'
env:
APP_VERSION: ${{ needs.release-version.outputs.version }}
run: bun run scripts/write-chart-sandbox-images.ts --version "${APP_VERSION}" --verify

- name: Configure Git
if: steps.pages.outputs.exists == 'true'
env:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,6 @@ __pycache__/
# `apps/sim/lib/uploads/` — 61 files of tracked source — and silently ignore
# anything added there later.
/uploads

# Written at chart publish by scripts/write-chart-sandbox-images.ts; never committed.
/helm/sim/files/sandbox-images.json
2 changes: 1 addition & 1 deletion apps/docs/content/docs/platform/enterprise/self-hosted.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Each feature is one server variable. Permission groups also turn on organization

### Sandbox readiness

A Sandbox entitlement also requires a remote execution provider with credentials and an immutable Function base image. Until the server verifies readiness, the Function block offers no **Shell** language, and **Settings → Sandboxes** shows an upgrade notice instead of a sandbox list.
Shell needs only a ready remote execution provider (credentials and an immutable Function base image), not the Sandbox entitlement: the Function block offers it once the server verifies that provider. Custom sandboxes need both the entitlement and the ready provider; until then **Settings → Sandboxes** shows an upgrade notice instead of a sandbox list.

JavaScript without `import`, `require`, a selected sandbox, or a sandbox file-path reference runs in local Node child workers in the app container when Sandbox flags are off. Python, Shell, JavaScript with external imports, and selected custom Sandboxes require the remote Function base and fail with a configuration error until it is ready. See [Sandboxes](/platform/self-hosting/sandboxes).

Expand Down
43 changes: 35 additions & 8 deletions apps/docs/content/docs/platform/self-hosting/sandboxes.mdx

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions apps/docs/content/docs/workflows/blocks/function.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ the configured Debian repositories.

JavaScript is the default. The language field is part of the saved workflow and is
never removed when Sandbox configuration changes. Python remains available as a
language choice; Shell and custom Sandbox controls appear when a remote Function
sandbox provider is enabled. Reference an earlier output directly, with no quotes
language choice; Shell appears when a remote Function sandbox provider is ready.
The custom **Sandbox** selector also needs sandbox access (see
[Sandboxes](#sandboxes)). Reference an earlier output directly, with no quotes
around the tag, and read an environment variable with `{{VAR}}`:

<Tabs items={['JavaScript', 'Python', 'Shell']}>
Expand Down
11 changes: 9 additions & 2 deletions apps/docs/scripts/fixtures/content-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -175501,8 +175501,8 @@
{
"lang": "yaml",
"meta": null,
"sha256": "7682823a0d915778f2433bbd40d57c0fb2abd8ffdc82774a2ad8e0716b51b5df",
"bytes": 77,
"sha256": "367c0b8cc996a8dc240d3285d9bb77f38ad15eee8380c1477bcd84957dc25ec1",
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
"bytes": 174,
"line": 182
},
{
Expand Down Expand Up @@ -175553,6 +175553,13 @@
"sha256": "df790200d0bf869d634b8a6fb573356b2f2114cfada800837daf28aacac46198",
"bytes": 208,
"line": 401
},
{
"lang": "yaml",
"meta": null,
"sha256": "eecfe88b395d0c94f2b4b11d6c58d51fed7914a1bc13cca199dae94c55c9ae56",
"bytes": 299,
"line": 429
}
],
"links": [
Expand Down
26 changes: 26 additions & 0 deletions apps/sim/blocks/blocks/function.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { resetEnvFlagsMock, setEnvFlags } from '@sim/testing'
import { afterEach, describe, expect, it } from 'vitest'
import { CodeLanguage } from '@/lib/execution/languages'
import { FunctionBlock } from '@/blocks/blocks/function'

afterEach(resetEnvFlagsMock)

function languageIds(): string[] {
const options = FunctionBlock.subBlocks.find((subBlock) => subBlock.id === 'language')?.options
if (typeof options !== 'function') throw new Error('language options are static')
return options().map((option) => option.id)
}

describe('Function language options', () => {
it('offers Shell when a remote provider is ready, without the custom-Sandbox entitlement', () => {
setEnvFlags({ isRemoteSandboxEnabled: true, isSandboxesEnabled: false })

expect(languageIds()).toContain(CodeLanguage.Shell)
})

it('hides Shell when no remote provider is ready, even with the entitlement', () => {
setEnvFlags({ isRemoteSandboxEnabled: false, isSandboxesEnabled: true })

expect(languageIds()).not.toContain(CodeLanguage.Shell)
})
})
2 changes: 1 addition & 1 deletion apps/sim/blocks/blocks/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const FunctionBlock: BlockConfig = {
options: () => [
{ label: getLanguageDisplayName(CodeLanguage.JavaScript), id: CodeLanguage.JavaScript },
{ label: getLanguageDisplayName(CodeLanguage.Python), id: CodeLanguage.Python },
...(getDeploymentShape().features.sandboxes
...(getDeploymentShape().remoteCodeEnabled
? [{ label: getLanguageDisplayName(CodeLanguage.Shell), id: CodeLanguage.Shell }]
: []),
],
Expand Down
3 changes: 3 additions & 0 deletions apps/sim/instrumentation-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ export async function register() {
const { getConfiguredRedisUrl } = await import('@/lib/core/config/redis')
getConfiguredRedisUrl()

const { reportSandboxConfiguration } = await import('@/lib/core/config/env-capabilities.server')
reportSandboxConfiguration()

await initializeOpenTelemetry()

const { reportAccountTokenSealing } = await import('@sim/db/sealed-text')
Expand Down
3 changes: 3 additions & 0 deletions apps/sim/lib/api/contracts/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,11 @@ export const deploymentShapeSchema = z.object({
* for rolling compatibility with app versions that predate projecting them; readers
* treat absent as `false`. `e2bEnabled` means the selected sandbox provider runs Pi's
* cloud modes; it keeps the name it had before providers were selectable.
* `remoteCodeEnabled` means the selected provider runs Function code (Python, Shell,
* JavaScript with imports), independent of the custom-Sandbox entitlement.
*/
e2bEnabled: z.boolean().optional(),
remoteCodeEnabled: z.boolean().optional(),
slackExtendedScopes: z.boolean().optional(),
invitationsDisabled: z.boolean().optional(),
publicApiDisabled: z.boolean().optional(),
Expand Down
3 changes: 3 additions & 0 deletions apps/sim/lib/core/config/deployment-projection.dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ vi.hoisted(() => {
cohereConfigured: false,
registrationMode: 'closed-no-email',
e2bEnabled: true,
remoteCodeEnabled: true,
slackExtendedScopes: true,
invitationsDisabled: true,
features: {
Expand Down Expand Up @@ -55,6 +56,7 @@ import {
isOrganizationsEnabled,
isPiCloudEnabled,
isPublicApiDisabled,
isRemoteSandboxEnabled,
isSandboxesEnabled,
isSelfServeRegistrationClosed,
isSessionPoliciesEnabled,
Expand Down Expand Up @@ -89,6 +91,7 @@ describe('browser registration flags', () => {
describe('browser deployment switches', () => {
it('take the projected server answer over the browser environment', () => {
expect(isPiCloudEnabled).toBe(true)
expect(isRemoteSandboxEnabled).toBe(true)
expect(isSlackExtendedScopesEnabled).toBe(true)
expect(isInvitationsDisabled).toBe(true)
})
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/lib/core/config/deployment-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isOrganizationsEnabled,
isPiCloudEnabled,
isPublicApiDisabled,
isRemoteSandboxEnabled,
isSandboxesEnabled,
isScimEnabled,
isSessionPoliciesEnabled,
Expand Down Expand Up @@ -102,7 +103,8 @@ function browserFallbackShape(): DeploymentShape {
* this is the `env-flags` fallback, used only when no projection exists.
*
* `features.sandboxes` is Sandbox *availability* (entitlement and a ready remote
* provider), not the entitlement alone.
* provider), not the entitlement alone. `remoteCodeEnabled` is provider readiness
* alone: the Function runtimes (Python, Shell) need a provider, not the entitlement.
*/
export function resolveDeploymentShape(): DeploymentShape {
return {
Expand All @@ -113,6 +115,7 @@ export function resolveDeploymentShape(): DeploymentShape {
cohereConfigured: isCohereConfigured,
registrationMode: getRegistrationMode(),
e2bEnabled: isPiCloudEnabled,
remoteCodeEnabled: isRemoteSandboxEnabled,
slackExtendedScopes: isSlackExtendedScopesEnabled,
invitationsDisabled: isInvitationsDisabled,
publicApiDisabled: isPublicApiDisabled,
Expand Down
49 changes: 49 additions & 0 deletions apps/sim/lib/core/config/env-capabilities.server.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { resetEnvMock, setEnv } from '@sim/testing'
import { getMockLogger } from '@sim/testing/mocks/logger.mock'
import { afterAll, beforeEach, describe, expect, expectTypeOf, it } from 'vitest'
import {
getSelectedSandboxProviderId,
inspectConfiguredOAuthClient,
reportSandboxConfiguration,
requireConfiguredOAuthClient,
} from '@/lib/core/config/env-capabilities.server'

const capabilityLogger = getMockLogger('EnvCapabilities')

describe('server environment capabilities', () => {
beforeEach(() => {
setEnv({
Expand Down Expand Up @@ -79,4 +83,49 @@ describe('server environment capabilities', () => {
'Unknown SANDBOX_PROVIDER "modal". Expected one of: e2b, daytona'
)
})

describe('sandbox configuration report at boot', () => {
beforeEach(() => {
capabilityLogger.warn.mockClear()
setEnv({
SANDBOX_K8S_RUNTIME_CLASS: undefined,
SANDBOX_K8S_ALLOW_UNISOLATED: undefined,
TRIGGER_DEV_ENABLED: undefined,
E2B_ENABLED: undefined,
E2B_API_KEY: undefined,
})
})

it('stays silent when no sandbox provider is configured', () => {
reportSandboxConfiguration()

expect(capabilityLogger.warn).not.toHaveBeenCalled()
})

it('names the Trigger.dev conflict when Kubernetes sandboxes run with TRIGGER_DEV_ENABLED', () => {
setEnv({
SANDBOX_PROVIDER: 'kubernetes',
SANDBOX_K8S_RUNTIME_CLASS: 'gvisor',
TRIGGER_DEV_ENABLED: 'true',
})

reportSandboxConfiguration()

expect(capabilityLogger.warn).toHaveBeenCalledTimes(1)
expect(capabilityLogger.warn.mock.calls[0]?.[0]).toContain('provider is misconfigured')
expect(capabilityLogger.warn.mock.calls[0]?.[1]).toMatchObject({
error: expect.stringContaining('TRIGGER_DEV_ENABLED'),
})
})

it('names the missing field of a half-configured provider', () => {
setEnv({ SANDBOX_PROVIDER: 'daytona', DAYTONA_API_KEY: 'daytona-key' })

reportSandboxConfiguration()

expect(capabilityLogger.warn.mock.calls[0]?.[1]).toMatchObject({
error: expect.stringContaining('DAYTONA_FUNCTION_SNAPSHOT_ID'),
})
})
})
})
22 changes: 22 additions & 0 deletions apps/sim/lib/core/config/env-capabilities.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
type WireFallbackOptions,
wireFallback,
} from '@sim/deployment-config/env-capabilities'
import { createLogger } from '@sim/logger'
import { env } from '@/lib/core/config/env'
import { SELF_HOSTED_SANDBOX_DOCS_URL } from '@/lib/execution/remote-sandbox/docs'

const logger = createLogger('EnvCapabilities')

export function getConfiguredStorageProviderId() {
return requireCapability(STORAGE_CAPABILITY, env).providerId
Expand All @@ -37,6 +41,24 @@ export function getSelectedSandboxProviderId() {
throw new Error('Remote sandbox has no selected provider')
}

/**
* Logs why a configured remote sandbox cannot run (a half-set-up provider, a bad image ref,
* Kubernetes with `TRIGGER_DEV_ENABLED`), so the operator sees it at boot. Silent when no sandbox
* is configured.
*/
export function reportSandboxConfiguration(): void {
const { error, providerId } = inspectCapability(SANDBOX_CAPABILITY, env)
if (!error) return
logger.warn(
'Selected sandbox provider is misconfigured; the sandbox kinds it cannot serve will fail',
{
provider: providerId,
error: error.message,
docs: SELF_HOSTED_SANDBOX_DOCS_URL,
}
)
}

export function getConfiguredAsyncJobsProvider() {
return requireCapability(ASYNC_JOBS_CAPABILITY, env).providerId
}
Expand Down
9 changes: 6 additions & 3 deletions apps/sim/lib/core/config/env-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,18 @@ export const isForkingEnabled = enterpriseFeatures.forking
* (`SANDBOX_PROVIDER`, defaulting to E2B). Availability comes from THAT
* provider's declared requirements, so a Daytona-only deployment (E2B unset)
* still enables remote execution.
* Server-only: the browser cannot inspect provider credentials, and reads the
* combined Sandbox availability from the deployment-shape projection instead.
* The browser cannot inspect provider credentials, so it reads this answer from
* the deployment-shape projection (`remoteCodeEnabled`).
*
* Every provider requires its credential and dedicated Function base. The old
* Mothership shell template/snapshot names are intentionally not fallbacks: a
* deployment must build and configure the Function-owned image before exposing
* the runtime.
*/
export const isRemoteSandboxEnabled = isSandboxKindAvailable(env, 'function')
export const isRemoteSandboxEnabled = resolveServerSwitch(
isSandboxKindAvailable(env, 'function'),
'remoteCodeEnabled'
)

/**
* Whether the complete custom-Sandbox feature is available on this deployment.
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/lib/execution/remote-sandbox/docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** Self-hosted sandbox setup guide, named wherever a missing or broken sandbox stops a run. */
export const SELF_HOSTED_SANDBOX_DOCS_URL = 'https://docs.sim.ai/platform/self-hosting/sandboxes'
31 changes: 31 additions & 0 deletions apps/sim/lib/execution/remote-sandbox/kubernetes/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @vitest-environment node
*/
import { describe, expect, it } from 'vitest'
import {
KubernetesSandboxConfigError,
toPodCreateError,
} from '@/lib/execution/remote-sandbox/kubernetes/errors'

const POLICY = 'sim-sim-sandbox-pods'

describe('toPodCreateError for an admission policy denial', () => {
it.each([
[
422,
`pods "sim-sbx-abc" is invalid: : ValidatingAdmissionPolicy '${POLICY}' with binding '${POLICY}' denied request: Every sandbox container must drop ALL capabilities.`,
],
[
403,
`pods "sim-sbx-abc" is forbidden: ValidatingAdmissionPolicy '${POLICY}' with binding '${POLICY}' denied request: Sandbox pods must not set sysctls.`,
],
])('names the policy and the chart/app version skew on a %i', (status, message) => {
const error = toPodCreateError({ status, message }, 'sim-sandboxes')

expect(error).toBeInstanceOf(KubernetesSandboxConfigError)
expect(error.message).toContain(`ValidatingAdmissionPolicy "${POLICY}"`)
expect(error.message).toContain('upgrade the Helm chart and app image together')
expect(error.message).not.toContain('SANDBOX_K8S_NODE_SELECTOR')
expect(error.message).not.toContain('sandbox Role')
})
})
Loading
Loading