Daytona persistent resumes do not refresh SCM auth
Summary
Daytona sandboxes use persistent resume/recover rather than Modal-style snapshot restore. On resume, we call Daytona startSandbox / recoverSandbox against the existing sandbox, so the sandbox keeps its previous filesystem, environment variables, git remotes, and runtime bootstrap state.
That means SCM auth is not refreshed on Daytona resume/recover.
Why this matters
Create-time SCM auth can expire while a Daytona sandbox is stopped, idle, or running for longer than the token TTL. Because resume/recover does not rebuild the environment or rewrite credentialed git remotes, later git operations can fail with stale credentials.
Modal snapshot restore is different: restore mints a fresh token and the restored entrypoint rewrites origin before fetching. This issue is specific to Daytona persistent resume/recover behavior.
Current behavior
- Fresh Daytona sandbox creation receives SCM auth setup.
- Daytona resume/recover only restarts or recovers the existing sandbox.
- No new clone token is resolved during resume.
- Existing env vars and credentialed remotes are preserved.
Expected behavior
On Daytona resume/recover, we should ensure SCM auth state is current before the agent performs git operations.
Possible fixes:
- Force a fresh Daytona sandbox when the previous create-time SCM auth may be expired.
- Add a resume-time auth refresh step that updates the sandbox's git auth state before git operations run.
- Track auth freshness/expiry in control-plane state and choose resume vs fresh spawn accordingly.
- Avoid relying on persisted env tokens/remotes for resumed Daytona sandboxes.
Impact
Users with Daytona persistent sandboxes can hit git auth failures after token expiry, especially after idle/resume or sandboxes running longer than the token TTL.
Relevant code references from current main (90473af):
- Daytona is explicitly modeled as persistent resume, not snapshot restore:
https://github.com/ColeMurray/background-agents/blob/90473afec5bdeb5140c18277efc7d3c2854af206/packages/control-plane/src/sandbox/providers/daytona-provider.ts#L52-L57
readonly capabilities: SandboxProviderCapabilities = {
supportsSnapshots: false,
supportsRestore: false,
supportsWarm: false,
supportsPersistentResume: true,
supportsExplicitStop: true,
};
- Fresh Daytona creation resolves SCM auth and injects it into the sandbox env:
https://github.com/ColeMurray/background-agents/blob/90473afec5bdeb5140c18277efc7d3c2854af206/packages/control-plane/src/sandbox/providers/daytona-provider.ts#L194-L245
private async buildEnvVars(config: CreateSandboxConfig): Promise<Record<string, string>> {
const cloneToken = await this.getCloneToken();
// ...
if (cloneToken) {
envVars.VCS_CLONE_TOKEN = cloneToken;
if (this.providerConfig.scmProvider === "github") {
envVars.GITHUB_APP_TOKEN = cloneToken;
envVars.GITHUB_TOKEN = cloneToken;
}
}
return envVars;
}
- The Daytona resume path only starts or recovers the existing sandbox; it does not call
buildEnvVars()or resolve a new clone token:
https://github.com/ColeMurray/background-agents/blob/90473afec5bdeb5140c18277efc7d3c2854af206/packages/control-plane/src/sandbox/providers/daytona-provider.ts#L112-L135
async resumeSandbox(config: ResumeConfig): Promise<ResumeResult> {
// ...
const state = sandbox.state;
if ((state === "error" || state === "build_failed") && sandbox.recoverable) {
await this.client.recoverSandbox(config.providerObjectId);
} else if (state !== "started") {
await this.client.startSandbox(config.providerObjectId);
}
// ...
}
- The lifecycle manager only passes resume metadata into the provider; there is no repo/auth payload equivalent to fresh create:
https://github.com/ColeMurray/background-agents/blob/90473afec5bdeb5140c18277efc7d3c2854af206/packages/control-plane/src/sandbox/lifecycle/manager.ts#L731-L738
const result = await this.provider.resumeSandbox({
providerObjectId,
sessionId: session.session_name || session.id,
sandboxId: sandbox.modal_sandbox_id,
timeoutSeconds,
codeServerEnabled: session.code_server_enabled === 1,
sandboxSettings: this.parseSandboxSettings(session),
});
- The Daytona REST client start/recover calls do not include an env update body:
https://github.com/ColeMurray/background-agents/blob/90473afec5bdeb5140c18277efc7d3c2854af206/packages/control-plane/src/sandbox/daytona-rest-client.ts#L140-L149
async startSandbox(id: string): Promise<void> {
await this.request<void>("POST", `/sandbox/${id}/start`, TIMEOUT_START_MS);
}
async recoverSandbox(id: string): Promise<void> {
await this.request<void>("POST", `/sandbox/${id}/recover`, TIMEOUT_RECOVER_MS);
}
For contrast, Modal restore resolves a fresh token per restore request and passes it into the restore path:
https://github.com/ColeMurray/background-agents/blob/90473afec5bdeb5140c18277efc7d3c2854af206/packages/modal-infra/src/web_api.py#L467-L481
manager = SandboxManager()
clone_token = _resolve_clone_token()
handle = await manager.restore_from_snapshot(
snapshot_image_id=snapshot_image_id,
session_config=session_config,
sandbox_id=sandbox_id,
control_plane_url=control_plane_url,
sandbox_auth_token=sandbox_auth_token,
clone_token=clone_token,
Production-readiness review found this issue should remain a Daytona launch blocker until the live proof covers more than resume auth.
Additional code pointers from the review
packages/daytona-infra/src/toolchain.py:66installs OpenCode, code-server, agent-browser, and helpers, but does not installttyd.packages/modal-infra/src/images/base.py:153installsttydfor the Modal runtime.packages/sandbox-runtime/src/sandbox_runtime/entrypoint.py:729expectsttydwhen terminal support is enabled.packages/control-plane/src/sandbox/providers/daytona-provider.ts:200does not setTERMINAL_ENABLED.packages/control-plane/src/sandbox/providers/daytona-provider.ts:258returns code-server tunnel data but nottydUrl.
Why this matters
Even after SCM auth refresh is fixed, Daytona should not be considered production-ready unless the provider explicitly documents disabled terminal support or reaches parity with Modal terminal/tunnel behavior. Otherwise the provider can look compatible while terminal support silently cannot work.
Suggested acceptance criteria to fold into this issue or a follow-up
- Persistent Daytona resume refreshes SCM credentials without requiring sandbox rebuild.
- Live proof covers clone, setup/start, first prompt, push branch/PR, snapshot or persistent resume, and SCM credential refresh after resume.
- Terminal support is either explicitly disabled and hidden for Daytona, or
ttydis installed, tunneled, signed, returned asttydUrl, and covered by live smoke. - The Daytona production evidence bundle references the exact staging run and commit tested.
Related production-readiness issues filed from the same review: #768, #769, #770, #771, #772, #773, #774, #775.
Resolved by the current brokered SCM credential flow. Daytona sandboxes no longer rely on a create-time SCM token for normal git operations: the sandbox Git credential helper requests short-lived credentials from the control plane on demand, refreshes them before expiry, and rewrites persisted remotes to token-free HTTPS URLs during repository boot. This runs before repository synchronization when a current Daytona sandbox starts or recovers.\n\nFocused verification passed for the Daytona provider, SCM credential service, GitHub App token handling, credential-helper refresh behavior, and repository boot behavior (59 control-plane tests and 93 sandbox-runtime tests).\n\nPersistent Daytona sandboxes created before the credential-helper rollout may retain the legacy runtime. We are intentionally not supporting those legacy sandboxes; they must be replaced with a sandbox created from the current base snapshot.