Skip to content

feat(vercel/sandbox): fix interactive shell#236

Merged
marc-vercel merged 3 commits into
mainfrom
sandboxes-fix-interactive-shell
Jun 30, 2026
Merged

feat(vercel/sandbox): fix interactive shell#236
marc-vercel merged 3 commits into
mainfrom
sandboxes-fix-interactive-shell

Conversation

@marc-vercel

Copy link
Copy Markdown
Collaborator

Fix interactive shell, so that we render the Vercel icon correctly between different shells.

Before, with a custom image:

▲ \[\e[2m\]\w/\[\e[0m\] 

Now:

▲ /app

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sandbox Ready Ready Preview, Comment, Open in v0 Jun 30, 2026 9:06am
sandbox-cli Ready Ready Preview, Comment, Open in v0 Jun 30, 2026 9:06am
sandbox-sdk-ai-example Ready Ready Preview, Comment, Open in v0 Jun 30, 2026 9:06am
workflow-code-runner Ready Ready Preview, Comment, Open in v0 Jun 30, 2026 9:06am

Comment thread .changeset/interactive-prompt-posix-portable.md Outdated
Co-authored-by: Andy <76787794+AndyW22@users.noreply.github.com>
Comment thread packages/sandbox/src/interactive-shell/interactive-shell.ts Outdated
…t readline non-printing markers, so bash overcounts the prompt width and miscalculates cursor position on long/wrapping lines and during line editing.

This commit fixes the issue reported at packages/sandbox/src/interactive-shell/interactive-shell.ts:25

## Bug

In `packages/sandbox/src/interactive-shell/interactive-shell.ts` the prompt was changed to:

```ts
const PS1 = `▲ \x1b[2m$PWD/\x1b[0m `;
```

This is sent verbatim as the `PS1` env var to the interactive session's shell.

The color escape sequences `\x1b[2m` (dim) and `\x1b[0m` (reset) are invisible but occupy ~4 bytes each on the wire. Bash's readline counts **every** character in `PS1` toward the displayed prompt width *unless* it is wrapped in the non-printing markers `[ ... ]` (which bash decodes into the raw readline bytes `\001` = `RL_PROMPT_START_IGNORE` and `\002` = `RL_PROMPT_END_IGNORE`).

The previous prompt correctly used those markers: `▲ [\e[2m]\w/[\e[0m]` . The new one dropped them.

### Failure mode / trigger

When the customer image's `/bin/sh` is **bash** (very common), readline now believes the prompt is ~8 columns wider than it actually is. Concrete symptoms:

*   Typing a command line long enough to wrap past `$COLUMNS` causes the cursor to land on the wrong column / row.
*   Pressing Up/Down through history, or editing (Ctrl-A, arrow keys) on a wrapped line, redraws at the wrong position, leaving visual garbage.

It is reproducible whenever the typed line length approaches the terminal width. Severity is cosmetic (no data loss), but it is a real, deterministic regression for bash sessions.

### Why the PR removed the markers

The intent was portability: `[`, `]`, `\e`, `\w` are bash-specific and are printed literally by dash/busybox-ash, so the old prompt rendered raw escape text under those shells. Using literal ESC bytes + `$PWD` fixes that for non-bash shells.

## Fix

Wrap the escape sequences in the **raw** readline ignore bytes `\x01`/`\x02` rather than the bash-only `[`/`]` text macros:

```ts
const PS1 = `▲ \x01\x1b[2m\x02$PWD/\x01\x1b[0m\x02 `;
```

*   **bash**: `\x01`/`\x02` *are* `RL_PROMPT_START_IGNORE`/`RL_PROMPT_END_IGNORE` — exactly the bytes that `[`/`]` decode to — so readline correctly excludes the escapes from prompt-width tracking. Width math is restored.
*   **dash / busybox-ash / zsh**: these are C0 control characters (SOH/STX) that terminal emulators render as non-printing, so the visible prompt is unchanged and `$PWD` + color still render. This keeps the cross-shell portability the PR was aiming for.

This achieves both goals with a single PS1 string, so the limitation noted in the issue (no string works across bash and dash) turns out to be avoidable using the raw readline markers instead of the bash-specific text form.


Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: marc-vercel <marc.codina@vercel.com>
@marc-vercel marc-vercel merged commit a69e91a into main Jun 30, 2026
12 checks passed
@marc-vercel marc-vercel deleted the sandboxes-fix-interactive-shell branch June 30, 2026 09:06
@github-actions github-actions Bot mentioned this pull request Jun 30, 2026
marc-vercel pushed a commit that referenced this pull request Jun 30, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## sandbox@3.3.1

### Patch Changes

- Fix the interactive shell prompt so that it is built from
POSIX-portable primitives — it renders correctly regardless of which
POSIX compatible shell (`bash`, `dash`, busybox `ash`) a custom image
ships as `/bin/sh`. ([#236](#236))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants