From c1e92371e315192d7d04049aa86dadb6a64541fc Mon Sep 17 00:00:00 2001 From: nisolanki1209 Date: Wed, 4 Mar 2026 11:43:48 +0530 Subject: [PATCH 1/2] feat(BREV-2866): open shell in expected container working directory --- pkg/cmd/shell/shell.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/shell/shell.go b/pkg/cmd/shell/shell.go index 22db1ac7..42f1b22a 100644 --- a/pkg/cmd/shell/shell.go +++ b/pkg/cmd/shell/shell.go @@ -120,7 +120,7 @@ func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID // legacy environments wont support this and cause errrors, // but we don't want to block the user from using the shell _ = writeconnectionevent.WriteWCEOnEnv(sstore, workspace.DNS) - err = runSSH(sshName) + err = runSSH(sshName, host) if err != nil { return breverrors.WrapAndTrace(err) } @@ -144,9 +144,15 @@ func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID return nil } -func runSSH(sshAlias string) error { +func runSSH(sshAlias string, host bool) error { sshAgentEval := "eval $(ssh-agent -s)" - cmd := fmt.Sprintf("%s && ssh %s", sshAgentEval, sshAlias) + var cmd string + if host { + cmd = fmt.Sprintf("%s && ssh %s", sshAgentEval, sshAlias) + } else { + // SSH into VM and respect container WORKDIR if containerized, otherwise use default directory + cmd = fmt.Sprintf("%s && ssh -t %s 'DIR=$(readlink -f /proc/1/cwd 2>/dev/null || pwd); cd \"$DIR\" || echo \"Warning: Could not access container directory\" >&2; exec ${SHELL:-/bin/sh}'", sshAgentEval, sshAlias) + } sshCmd := exec.Command("bash", "-c", cmd) //nolint:gosec //cmd is user input sshCmd.Stderr = os.Stderr From f2209a42114011c7492d972d367dc03e5c76c33c Mon Sep 17 00:00:00 2001 From: nisolanki1209 Date: Wed, 4 Mar 2026 15:33:39 +0530 Subject: [PATCH 2/2] feat(BREV-2866): preserve login shell environment --- pkg/cmd/shell/shell.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/shell/shell.go b/pkg/cmd/shell/shell.go index 42f1b22a..90fbb79a 100644 --- a/pkg/cmd/shell/shell.go +++ b/pkg/cmd/shell/shell.go @@ -151,7 +151,7 @@ func runSSH(sshAlias string, host bool) error { cmd = fmt.Sprintf("%s && ssh %s", sshAgentEval, sshAlias) } else { // SSH into VM and respect container WORKDIR if containerized, otherwise use default directory - cmd = fmt.Sprintf("%s && ssh -t %s 'DIR=$(readlink -f /proc/1/cwd 2>/dev/null || pwd); cd \"$DIR\" || echo \"Warning: Could not access container directory\" >&2; exec ${SHELL:-/bin/sh}'", sshAgentEval, sshAlias) + cmd = fmt.Sprintf("%s && ssh -t %s 'DIR=$(readlink -f /proc/1/cwd 2>/dev/null || pwd); cd \"$DIR\" || echo \"Warning: Could not access container directory\" >&2; exec -l ${SHELL:-/bin/sh}'", sshAgentEval, sshAlias) } sshCmd := exec.Command("bash", "-c", cmd) //nolint:gosec //cmd is user input