Skip to content

Commit b515c00

Browse files
committed
fallbac to homedir instead of /tmp
1 parent 3f74569 commit b515c00

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

packages/sandbox-container/src/session.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export interface SessionOptions {
5151
*
5252
* Note: This only affects where the shell starts. Individual commands can
5353
* specify their own cwd via exec options, and the shell can cd anywhere.
54-
* If the directory doesn't exist, the session falls back to /tmp.
54+
* If the specified directory doesn't exist when the session initializes,
55+
* the session will fall back to the home directory.
5556
*/
5657
cwd?: string;
5758

@@ -143,22 +144,22 @@ export class Session {
143144
this.sessionDir = join(tmpdir(), `session-${this.id}-${Date.now()}`);
144145
await mkdir(this.sessionDir, { recursive: true });
145146

146-
// Determine working directory. If the requested
147-
// cwd doesn't exist, we fall back to /tmp since it's always available and
148-
// safer than / for accidental operations.
147+
// Determine working directory. If the requested cwd doesn't exist, we fall
148+
// back to the home directory since it's a natural default for shell sessions.
149+
const homeDir = process.env.HOME || '/root';
149150
let cwd = this.options.cwd || CONFIG.DEFAULT_CWD;
150151
try {
151152
await stat(cwd);
152153
} catch {
153154
this.logger.debug(
154-
`Shell startup directory '${cwd}' does not exist, using '/tmp'`,
155+
`Shell startup directory '${cwd}' does not exist, using '${homeDir}'`,
155156
{
156157
sessionId: this.id,
157158
requestedCwd: cwd,
158-
actualCwd: '/tmp'
159+
actualCwd: homeDir
159160
}
160161
);
161-
cwd = '/tmp';
162+
cwd = homeDir;
162163
}
163164

164165
// Spawn persistent bash with stdin pipe - no IPC or wrapper needed!

tests/e2e/workspace-deletion-workflow.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ describe('Workspace Deletion Workflow (Issue #288)', () => {
339339
* Test 6: New session can be created when /workspace doesn't exist
340340
*
341341
* This tests the core fix for issue #288: when a new session is created
342-
* and /workspace doesn't exist, it should fall back to / instead of failing.
342+
* and /workspace doesn't exist, it should fall back to the home directory
343+
* instead of failing.
343344
*
344345
* Note: This test uses a different sandbox ID to ensure a completely new
345346
* session is created (not reusing an existing one).
@@ -377,7 +378,8 @@ describe('Workspace Deletion Workflow (Issue #288)', () => {
377378
* This is the PRIMARY test for issue #288. The bug was that creating a NEW session
378379
* after /workspace was deleted would fail with "Unknown Error, TODO".
379380
*
380-
* The fix makes session initialization fall back to "/" if /workspace doesn't exist.
381+
* The fix makes session initialization fall back to the home directory if
382+
* /workspace doesn't exist.
381383
*
382384
* IMPORTANT: This test actually deletes /workspace and creates a new session.
383385
* It restores /workspace at the end to avoid breaking other tests.
@@ -450,7 +452,7 @@ describe('Workspace Deletion Workflow (Issue #288)', () => {
450452
);
451453
expect(newSessionData.stderr?.toLowerCase() || '').not.toContain('todo');
452454

453-
// Step 5: Verify the new session fell back to "/" as working directory
455+
// Step 5: Verify the new session fell back to home directory
454456
const pwdResponse = await fetch(`${workerUrl}/api/execute`, {
455457
method: 'POST',
456458
headers: newHeaders,
@@ -461,8 +463,8 @@ describe('Workspace Deletion Workflow (Issue #288)', () => {
461463
expect(pwdResponse.status).toBe(200);
462464
const pwdData = (await pwdResponse.json()) as ExecResult;
463465
expect(pwdData.success).toBe(true);
464-
// Session should have fallen back to / since /workspace didn't exist
465-
expect(pwdData.stdout?.trim()).toBe('/');
466+
// Session should have fallen back to /root since /workspace didn't exist
467+
expect(pwdData.stdout?.trim()).toBe('/root');
466468

467469
// Step 6: Restore /workspace for other tests
468470
const restoreResponse = await fetch(`${workerUrl}/api/execute`, {

0 commit comments

Comments
 (0)