Repository navigation
feat(sandbox): self-hosted Kubernetes sandbox provider - #10683
waleedlatif1 wants to merge 78 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Confidence Score: 4/5
[High impact] The PR adds a new route for user-authored sandbox work to run on self-hosted Kubernetes clusters. Fix the session deadline overwrite and the repository-rule violations before merging. Findings
SummaryAdds an opt-in Kubernetes sandbox provider, an in-pod agent, release images, and Helm isolation controls.
The previous-review ancestry checks did not pass, so this assessment covers the full PR. Verification was by source inspection; no tests were run.
|
There was a problem hiding this comment.
All reported issues were addressed across 140 files
This PR changes infrastructure or deployment configuration. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.
Turn on auto-fix | Re-trigger cubic
1c10cea to
2068378
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 142 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
2068378 to
ff29fc6
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
4 issues found across 146 files
Confidence score: 3/5
- In
sandbox-kubernetes.yaml, numeric-only namespace and RuntimeClass names can render as numbers where Kubernetes requires strings, causing the generated resources to be invalid. Quote these values in the templates. - In
values.yaml, an existing custom RuntimeClass with a non-built-in handler fails isolation because the chart only setsSANDBOX_K8S_TRUSTED_RUNTIME_HANDLERSwhen it creates the RuntimeClass. Pass the configured handler even whenruntimeClass.createis false. - In
sandbox-images.yml, changes tobun.lockor workspace manifests can changesandbox-agentwithout triggering an image rebuild, leaving the old signed image in use. Add those dependency inputs to the path filter.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="helm/sim/templates/sandbox-kubernetes.yaml">
<violation number="1" location="helm/sim/templates/sandbox-kubernetes.yaml:72">
P2: Quote `.Release.Namespace` in the RoleBinding subjects and the NetworkPolicy `matchLabels` value; otherwise installs in a numeric-only release namespace render invalid string fields.</violation>
<violation number="2" location="helm/sim/templates/sandbox-kubernetes.yaml:108">
P2: Quote `$runtimeClassName` when creating the RuntimeClass so schema-valid numeric-only names produce a valid Kubernetes string field.</violation>
</file>
<file name="helm/sim/values.yaml">
<violation number="1" location="helm/sim/values.yaml:1242">
P2: An existing `custom` RuntimeClass with a non-built-in handler always fails isolation because the chart emits `SANDBOX_K8S_TRUSTED_RUNTIME_HANDLERS` only when `runtimeClass.create` is true. Pass the configured handler for existing classes or add a separate trusted-handler value.</violation>
</file>
<file name=".github/workflows/sandbox-images.yml">
<violation number="1" location=".github/workflows/sandbox-images.yml:27">
P2: This path filter misses agent dependency inputs: changes to `bun.lock` or workspace manifests can alter `sandbox-agent` without changing `images.generated.json`, so pushes keep serving the old signed image. Include every install input in the content hash or trigger this workflow for those files.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
ff29fc6 to
9e0b54f
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 147 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
…lared provider traits - Sandbox kind availability (function, mothership, doc, pi) comes from the selected provider's declarations in deployment-config instead of e2b/daytona branches in env-flags. Pi cloud gates on the selected provider running Pi; E2B keeps its exact prior gate (E2B_ENABLED), Daytona now needs DAYTONA_PI_SNAPSHOT_ID. The projected deployment-shape key stays e2bEnabled. - Session-command recovery goes through an optional SandboxProvider.stopSessionProcess that E2B implements with its existing stop. - SandboxProviderId derives from SANDBOX_PROVIDER_IDS; CLI recipes, metrics, Pi lifetime ceilings, and pricing key off it, and pricing accepts an operator-paid provider priced at zero. - sim-setup derives the disabled condition, option order, and provider validation from SANDBOX_CAPABILITY.
…ument Pi visibility - Decision-table test for isSandboxKindAvailable covering E2B on/off per kind, Daytona with and without its Pi snapshot, and Daytona with a leftover E2B_ENABLED. - deployment-config fails type-check when SANDBOX_PROVIDER_IDS and the sandbox capability's providers diverge. - CLI recipes default to an explicit verified provider list again. - Docs: Pi cloud modes appear when the selected provider is enabled with its Pi image; E2B_ENABLED alone still suffices on E2B. - Session recovery TSDoc notes it uses the selected provider; conformance Daytona budgets assert literal values; minor TSDoc and status nits.
…ges for the Kubernetes provider Render docker/sandbox-function.Dockerfile and docker/sandbox-pi.Dockerfile from the single-source package lists the E2B and Daytona builders consume, behind a generate:sandbox-dockerfiles / check:sandbox-dockerfiles pair. Both images use the Daytona base digest, run the Daytona install steps and build-time asserts, install Node from a checksum-verified archive per architecture, add the E2B user (uid/gid 1000, home /home/user), and keep root as the default user. The agent binary is injected by the pod's initContainer, not baked in. The Function Python surface is pinned by function-sandbox-manifest.json, in the parity-manifest format Daytona takes from an accepted E2B run. The generator also writes apps/sim/lib/execution/remote-sandbox/kubernetes/images.generated.json, mapping each kind (function, pi, agent) to ghcr.io/simstudioai/sandbox-<kind>:<tag>, where the tag is the first 16 hex chars of a sha256 over the image's declared inputs, so a Sim release references exact images without a per-release build. verify-sandbox-image.ts checks a built image with the local Docker daemon: root default user, the uid 1000 contract, and the Function parity probe against the manifest (or the Pi runtime asserts). E2B and Daytona builders are unchanged.
… a free port The stand-in agent bound the protocol's fixed port 49983, inside the ephemeral range, so any process holding it failed the whole file with EADDRINUSE (reproduced by holding the port). It now binds port 0 and a mocked agentBaseUrl routes the pod IP to it, as the pod network would. The comment claiming the provider reads the port from the pod spec was wrong: it uses the protocol constant.
…ripts The two watch-backoff tests started the pod on a fixed 2.5 s and 1.5 s timer that raced the provider's jittered backoff (up to 2.1 s across three watches before request time), so a slow run could start the pod before the last scripted watch was followed and fail. They now wait until the provider has made the required number of watches, then start the pod.
…ing writer The growing-file read test appended from a background shell loop, so whether the file grew between open and read depended on scheduling. It now appends 8 MiB of 'b' right after the response declares the size at open and requires the body to match that size with no 'b' in it. A mutant that reads to EOF fails it (40 MiB sent against 32 MiB declared).
…s coalesce The test wrote 20 bytes ten times against a 600-byte budget, which only overflows if the agent emits at least seven separate events (200 bytes plus 64 per event); event-loop lag that merged writes would let a byte-only charge pass. It now writes one byte ten times against a budget of one event's overhead (64): the bytes alone fit, and the first event of any size exceeds it. Dropping the overhead charge fails the test.
The descendant-cleanup command slept 0.3 s so the backgrounded subshell could record its pid before the command exited; a slow scheduler left the pid file short and the length assertion failed. The command now exits once the file holds all three pids, bounded at 5 s.
…igns startProxy and the bad-gateway server asked freePort for a port, closed it, then listened on it again, leaving a window for another process to take it. They now listen on port 0 and read the assigned port back. freePort is left private to startTestAgent, which must name the agent's port up front.
- event-stream: require the proxy to have seen a read, so renaming the events field cannot leave highestRead at -1 and pass vacuously (proved by pointing the proxy at another property). - function-sandbox-packages: drop the two assertions that restated the pinned Python and Node version literals and match any Python version in the digest-pinned base image reference; the parity script already checks the versions against the manifest. - kubernetes live suite: import createRouteContext from its helper file rather than the @sim/testing barrel.
…tier The Kubernetes leg starts a real sim-sandbox-agent per pod and drives it over loopback HTTP with real timers, which the unit tier rules out and which the unit job runs under the most contention (8 vCPUs shared by about 7 workers, with child_process wrapped for test selection). Its precedent, the agent handle suite, is an integration file. The scenario table moves to conformance.test-helpers.ts (the workspace-source.test-helpers.ts pattern), registered per provider: conformance.test.ts runs it on E2B and Daytona with their SDK-only tests, and conformance.integration.ts runs it on Kubernetes with the stand-in cluster. All 271 test names and outcomes are unchanged: 199 E2B, Daytona and shared tests in the unit file, and the 66 Kubernetes scenarios plus 6 skipped SDK-only ones in the integration file. The Kubernetes e2e workflow's path filter excludes all three conformance files, as it excluded the one.
The teardown froze the agent, then awaited a timer between sweeps, which let test code (such as a request body still uploading) run against a frozen agent whose socket stays open. The sweep is now synchronous from SIGSTOP to the agent's SIGKILL, each ps call pacing the next pass.
…stops after the refusal
…w sandboxes docs examples
- Raise a pod's expires-at only monotonically, conditioned on the read resourceVersion, so a handle with an older deadline cannot shorten one another handle on the same session pod recorded. - Verify RuntimeClass isolation before reusing a session pod, and let each caller of the shared isolation check abort only its own wait. - Run the provider suite in the integration tier: it drives real loopback HTTP servers and real timers. - Report non-UTF-8 NDJSON lines as NdjsonDecodeError. - Let an output callback's error fail the command (stopping it) instead of reading as a dropped stream. - Close a file read's descriptor when a read fails, and finish partial writes before committing an upload. - Tighten the sandbox chart schema (positive quantities, string node selector values, toleration fields, RuntimeClass name) and quote the sandbox namespace name wherever it renders. - Fail the live-suite preflight when the identity can exec into sandboxes, and fail the image workflow when the PR file listing cannot be read.
…tories A one-shot Kubernetes shell run fetches URL mounts with a root shell whose `mkdir -p` leaves /tmp/sim/inputs root-owned 0755, so a later inline mount into the same directory, written by the agent's uid-1000 file worker, failed with EACCES. E2B's envd (root) creates missing parents owned by the target user, and Daytona runs everything as root, so neither hits it. The agent now reads SIM_SANDBOX_AGENT_USER_DIRS (comma-separated absolute paths, scrubbed from children with the other SIM_SANDBOX_* variables). As root, before serving, it creates each missing directory and missing parent and chowns only what it created to the sandbox user; existing directories keep their owner. Invalid entries fail startup. The Kubernetes pod sets it to the mount input and output directories. Shared mount code is unchanged.
- Pull the release's default sandbox images through global.imageRegistry: the chart passes it as SANDBOX_K8S_IMAGE_REGISTRY and the provider moves the published agent, Function, and Pi refs to it; set images stay as given. - Refuse runtimeClass.create when the chart has no RuntimeClass name. - Reject a file worker `end` frame for a call with no answered read stream, so a malformed reply restarts the worker and rejects the call. - Make the fake Kubernetes API require the kubeconfig's bearer token. - Run the Kubernetes sandbox e2e for the migrations Dockerfile, the image build action, and the CI Helm defaults.
9e0b54f to
ef2af31
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
1 issue found across 148 files
Confidence score: 3/5
kubernetesQuantityValueinpackages/deployment-config/src/env-capabilities.tsaccepts overflowing values such as1e9999, sohalfQuantitycan emit invalidInfinityresource quantities in pod requests. Reject non-finite parsed values.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/deployment-config/src/env-capabilities.ts">
<violation number="1" location="packages/deployment-config/src/env-capabilities.ts:1116">
P2: `kubernetesQuantityValue` treats overflowing quantities as valid: `1e9999` becomes `Infinity`, and the capability validation accepts it. `halfQuantity` then emits `Infinitym` or `Infinity`, so the first pod request is rejected instead of configuration failing early; return `null` for non-finite results.</violation>
</file>
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Turn on auto-fix | Re-trigger cubic
… shared-kernel choice
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 148 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Turn on auto-fix | Re-trigger cubic
Summary
kubernetessandbox provider so self-hosters get Python, shell, JS imports, file mounts and outputs, Pi, and the Mothership workbench without E2B or Daytona ([Feature Request] Replace E2B with local Docker sandbox for self-hosted deployments #4965). Opt-in withSANDBOX_PROVIDER=kubernetes; E2B, Daytona and no-provider deployments behave as before.isolated-sandbox, gVisor or Kata.pods/execRBAC and no service-account token in the sandbox. 24h hard cap. Finished and orphaned pods are swept by the existing session cleanup cron.apps/sandbox-agent,@sim/sandbox-agent-protocol): a small daemon with envd-like semantics (process start/reattach/signal, file API), injected by an initContainer so any image works.createAgentSandboxHandleimplementsSandboxHandleover it.E2B_ENABLED.images.generated.json(the agent's tag hashes its Dockerfile and shipped bundle). Published, signed and attested from their ownsandbox-images.yml;ci.ymlis untouched.sandbox.kubernetes.*, off by default; the default render is identical apart from the chart version. Adds the namespace, least-privilege Role (pods, events list), sandbox NetworkPolicy withinternet/restrictedegress profiles (private, link-local and metadata ranges blocked), quota, LimitRange max, PSA baseline, admission policy and optional pre-pull.Type of Change
Testing
conformance.integration.ts.sandbox-kubernetes-e2e.yml, k3s + gVisor):Checklist
test-auditauthoring gate)