Skip to content

Commit e9c08b4

Browse files
authored
Prevent shell inception from happening (#2643)
## Summary Running `devbox shell` inside a devbox shell is strictly prohibited 😆 ## How was it tested? `go build -o devbox cmd/devbox/main.go` `devbox shell` `devbox shell` again ## Is this change backwards-compatible? Yes
1 parent 9f0decc commit e9c08b4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

boxcli/shell.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package boxcli
55

66
import (
77
"fmt"
8+
"os"
89

910
"github.com/pkg/errors"
1011
"github.com/spf13/cobra"
@@ -29,7 +30,12 @@ func runShellCmd(cmd *cobra.Command, args []string) error {
2930
return errors.WithStack(err)
3031
}
3132

33+
inDevboxShell := os.Getenv("DEVBOX_SHELL_ENABLED")
34+
if inDevboxShell != "" && inDevboxShell != "0" && inDevboxShell != "false" {
35+
return errors.New("You are already in an active devbox shell.\nRun 'exit' before calling devbox shell again. Shell inception is not supported.")
36+
}
37+
3238
fmt.Println("Installing nix packages. This may take a while...")
33-
// TODO: If we're inside a devbox shell already, don't re-run.
39+
3440
return box.Shell()
3541
}

0 commit comments

Comments
 (0)