Skip to content

support custom sandbox entrypoint command #848

@matifali

Description

@matifali

Problem Statement

The sandbox always runs sleep infinityhardcoded in the k8s driver. There's no API field to override this.
I'm integrating Coder workspaces with OpenShell sandboxes via the Terraform provider. The e2e flow works but the Coder agent has to be manually bootstrapped after sandbox creation — there's no way to run a custom entrypoint at startup. The only workaround is openshell sandbox exec after the sandbox reaches Ready, which can't be expressed declaratively in Terraform.
I imagine this would affect any orchestrator that needs to run a process inside the sandbox at creation time.

Proposed Design

I think the minimal change would be adding a command field to SandboxSpec and threading it through to the k8s driver. When set, the driver writes it to OPENSHELL_SANDBOX_COMMAND instead of sleep infinity. When empty, behavior is unchanged.
The sandbox supervisor already reads from OPENSHELL_SANDBOX_COMMAND and supports arbitrary commands — the gap is just that the k8s driver always overwrites it.
The files I think would need changes (though I might be missing something):

  • proto/openshell.proto — add repeated string command to SandboxSpec
  • proto/compute_driver.proto — add the same to DriverSandboxSpec
  • crates/openshell-server/src/compute/mod.rs — pass it through driver_sandbox_spec_from_public
  • crates/openshell-driver-kubernetes/src/driver.rs — use spec.command in apply_required_env instead of the hardcoded value

Alternatives Considered

  1. Override via environment map — I tried passing OPENSHELL_SANDBOX_COMMAND through the sandbox's environment field in Terraform. Doesn't work — upsert_env in apply_required_env overwrites user-provided values.
  2. Post-creation exec — Using openshell sandbox exec after the sandbox reaches Ready. This works but adds latency, requires polling, and can't be automated declaratively through Terraform.
  3. Bake into the image — Tried building a custom image with an entrypoint. The sandbox supervisor ignores the image's ENTRYPOINT/CMD and runs OPENSHELL_SANDBOX_COMMAND directly.

Agent Investigation

  • Traced OPENSHELL_SANDBOX_COMMAND from the supervisor (crates/openshell-sandbox/src/main.rs) through the k8s driver (driver.rs:1284) — confirmed the hardcoding
  • The supervisor already supports arbitrary commands (CLI args → env var → /bin/bash fallback), so no supervisor changes should be needed
  • The gateway maps public spec → driver spec in driver_sandbox_spec_from_public (crates/openshell-server/src/compute/mod.rs:617)
  • Tested all three alternatives above against a live gateway (v0.0.28)

Checklist

  • I've reviewed existing issues and the architecture docs
  • This is a design proposal, not a "please build this" request

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions