Skip to content

[BUG] Sandbox Command Fails to Restore Working Directory After Execution #700

@sysprime10001

Description

@sysprime10001

Project

cortex

Description

When running a sandboxed command that changes the working directory internally (e.g., using cd), the Cortex CLI does not restore the original working directory after the sandbox exits. This causes subsequent commands to execute in an unexpected directory, leading to confusing behavior and incorrect file resolution.

Error Message

After exiting a sandboxed command, subsequent Cortex commands operate in a different directory than the one originally used to invoke the sandbox.

Debug Logs

System Information

Version: 0.1.0

Operating System
OS: Windows 11

Hardware
CPU: Intel(R) Xeon(R) E-2388G CPU @ 3.20GHz (16 cores)
RAM: 125 GB

Build Environment
Rust: rustc 1.92.0 (ded5c06cf 2025-12-08)
Target: x86_64

Environment
Standard interactive PowerShell session
No custom environment variables
Sandbox enabled with default settings

Screenshots

No response

Steps to Reproduce

  1. Open a terminal in C:\projects\cortex-test.
  2. Run a sandbox command that changes directories, such as: cortex sandbox windows -- cmd /c "cd C:\Windows && dir".
  3. Exit the sandboxed command normally.
  4. Run a Cortex command that relies on the current working directory (e.g., cortex run "list files").
  5. Observe the directory context used by the command.

Expected Behavior

After the sandboxed command finishes, Cortex should restore the original working directory from which the sandbox was launched.

Actual Behavior

The working directory remains altered after the sandbox exits, causing subsequent commands to run in an unexpected directory.

Additional Context

I am fully confident this behavior represents a valid and reasonable bug. From an AI systems perspective, maintaining execution context boundaries is essential for correctness and predictability, and failure to restore the working directory violates clear user expectations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions