Skip to content

Warn on sandbox exec when config file has drifted#401

Merged
robinaugh merged 1 commit intomainfrom
jason/sandbox-definition-drift
Mar 6, 2026
Merged

Warn on sandbox exec when config file has drifted#401
robinaugh merged 1 commit intomainfrom
jason/sandbox-definition-drift

Conversation

@robinaugh
Copy link
Contributor

@robinaugh robinaugh commented Mar 6, 2026

Completes RWX-7

Summary

  • When a sandbox is started, the CLI now hashes the config file (SHA-256) and stores it alongside the session in .rwx/sandboxes/sandboxes.json
  • On each rwx sandbox exec, the current config file is re-hashed and compared against the stored value
  • If they differ, a warning is printed to stderr directing the user to rwx sandbox reset
  • Pre-existing sessions without a stored hash gracefully skip the check (no warning)

Addresses the "changed the definition, didn't get picked up" problem discussed with Kyle — the most common sandbox pain point.

Test plan

  • TestHashConfigFile — verifies hash consistency, different content produces different hashes, missing file returns empty
  • TestService_ExecSandbox_DefinitionDrift — verifies warning on drift, no warning when unchanged, no warning when no stored hash (backwards compat)
  • Full unit test suite passes
  • Linter passes
  • Manual: start a sandbox, modify sandbox.yml, exec again — confirm warning appears
  • Manual: start a sandbox, exec without modifying config — confirm no warning

Manual test

╰─⠠⠵ ./rwx sandbox exec -- pwd
Started sandbox: 6d1a1d5bdf1f4623b3eccc248073e7fa
https://cloud.rwx.com/mint/rwx/runs/6d1a1d5bdf1f4623b3eccc248073e7fa
/var/mint-workspace
No changes to pull from sandbox.

# Make a change to sandbox.yml here

╰─⠠⠵ ./rwx sandbox exec -- pwd
Warning: .rwx/sandbox.yml has changed since this sandbox was started.
The running sandbox does not reflect these changes.
Run 'rwx sandbox reset' to apply the new definition.

/var/mint-workspace
No changes to pull from sandbox.

╰─⠠⠵ ./rwx sandbox reset && ./rwx sandbox exec -- pwd
Stopped old sandbox: 6d1a1d5bdf1f4623b3eccc248073e7fa
Started sandbox: afd62dfcb80b47ee9dc21b2e942ccceb
https://cloud.rwx.com/mint/rwx/runs/afd62dfcb80b47ee9dc21b2e942ccceb
/var/mint-workspace
No changes to pull from sandbox.

When a sandbox is started, hash the config file (SHA-256) and store it
in the session. On each exec, compare the current hash against the
stored one and print a warning if they differ, directing the user to
`rwx sandbox reset`.

Gracefully handles pre-existing sessions that lack a stored hash by
skipping the check entirely.
@robinaugh robinaugh self-assigned this Mar 6, 2026
@robinaugh robinaugh marked this pull request as ready for review March 6, 2026 14:50
}

// Warn if the sandbox definition has changed since this sandbox was started
if storedConfigHash != "" && configFile != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this consider whether you're providing different params? Not sure if it even supports --init I guess 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rwx sandbox technically does support --init but it's not documented/encouraged - I lean against building in a check for that here for now, what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's sort of odd in tandem with exec anyway I think

@robinaugh robinaugh merged commit 766005a into main Mar 6, 2026
1 check passed
@robinaugh robinaugh deleted the jason/sandbox-definition-drift branch March 6, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants