feat(sandbox): persist startup command across gateway stop/start cycles#753
Open
feat(sandbox): persist startup command across gateway stop/start cycles#753
Conversation
The user-provided command from `sandbox create -- <command>` was previously ephemeral—executed via SSH on first connect but lost when the sandbox pod was recreated after a gateway restart. This change persists the command in the SandboxSpec protobuf, stores it in both SQLite and the Kubernetes CRD, and sets it as OPENSHELL_SANDBOX_COMMAND in the pod spec. When the CRD controller recreates the pod after a gateway stop/start, the supervisor re-executes the stored command instead of falling back to `sleep infinity`.
johntmyers
reviewed
Apr 4, 2026
| } else { | ||
| sandbox_command.join(" ") | ||
| }; | ||
| upsert_env(env, "OPENSHELL_SANDBOX_COMMAND", &command_value); |
Collaborator
There was a problem hiding this comment.
do we run a risk of accidentally mangling the command when we retrieve it for execution and split on whitespace?
i.e. "python -c print('hello world')". => ["python", "-c", "print('hello", "world')"] due to
} else if let Ok(c) = std::env::var("OPENSHELL_SANDBOX_COMMAND") {
// Simple shell-like splitting on whitespace
c.split_whitespace().map(String::from).collect()
We basically only had sleep infinity as the sandbox entrypoint I think?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The user-provided command from
sandbox create -- <command>was previously ephemeral — executed via SSH on first connect but lost when the sandbox pod was recreated after a gateway restart. This change persists the command in theSandboxSpecso it survives gateway stop/start cycles.Related Issue
N/A — discovered during testing of sandbox pod resumption behavior.
Changes
proto/datamodel.proto: Addedrepeated string command = 10field toSandboxSpecto persistently store the user's startup commandcrates/openshell-cli/src/run.rs: Pass the CLI's trailing-- <command>args into theSandboxSpec.commandfield onCreateSandboxRequest. Since the command now runs as the sandbox entrypoint, the post-create flow opens an interactive shell instead of SSH-exec'ing the command a second timecrates/openshell-server/src/sandbox/mod.rs: Thread the command throughsandbox_to_k8s_spec→sandbox_template_to_k8s→build_env_list→apply_required_env. When a command is present,OPENSHELL_SANDBOX_COMMANDis set to the user's command instead ofsleep infinitycrates/openshell-cli/src/ssh.rs: Suppressed dead-code warning onsandbox_exec_without_exec(no longer called from the create flow)apply_required_env_uses_sleep_infinity_when_no_commandandapply_required_env_uses_user_command_when_providedTesting
mise run pre-commitpassesChecklist