Skip to content

Commit 3757bf2

Browse files
elsighclaude
andcommitted
Fix remaining lsof crashes in sandbox environments
Added isInSandbox() helper to mcp-server/app/mcp/tools.ts and wrapped all lsof-dependent code paths to skip in sandbox: - restart_dev_server MCP tool now returns error in sandbox - killPortProcess functions in dev-environment.ts skip lsof The lsof utility doesn't exist in Vercel Sandbox, Docker containers, and other constrained environments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 92bf8ea commit 3757bf2

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

mcp-server/app/mcp/tools.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ import { WebSocket } from "ws"
99

1010
const execAsync = promisify(exec)
1111

12+
/**
13+
* Detect if we're in a sandbox environment (Vercel Sandbox, Docker, etc.)
14+
* where lsof and other system utilities may not be available.
15+
*/
16+
function isInSandbox(): boolean {
17+
return (
18+
process.env.VERCEL_SANDBOX === "1" ||
19+
process.env.VERCEL === "1" ||
20+
existsSync("/.dockerenv") ||
21+
existsSync("/run/.containerenv")
22+
)
23+
}
24+
1225
// Tool descriptions
1326
export const TOOL_DESCRIPTIONS = {
1427
fix_my_app:
@@ -3902,6 +3915,19 @@ export async function restartDevServer(params: {
39023915
// Fallback: Use dev3000's own restart mechanism
39033916
logToDevFile("Restart Dev Server: Using dev3000 restart mechanism")
39043917

3918+
// In sandbox environments, lsof doesn't exist - skip process killing
3919+
if (isInSandbox()) {
3920+
logToDevFile("Restart Dev Server: Skipping lsof-based kill in sandbox environment")
3921+
return {
3922+
content: [
3923+
{
3924+
type: "text",
3925+
text: `⚠️ **RESTART NOT SUPPORTED IN SANDBOX**\n\nDev server restart is not supported in sandbox environments (Vercel Sandbox, Docker containers).\n\nThe \`lsof\` utility needed for process management is not available.\n\n💡 If running in Vercel Sandbox, the dev server is managed by the sandbox infrastructure.`
3926+
}
3927+
]
3928+
}
3929+
}
3930+
39053931
// Kill processes on the app port
39063932
const killCommand = `lsof -ti :${appPort} | xargs kill 2>/dev/null || true`
39073933
logToDevFile(`Restart Dev Server: Executing kill command: ${killCommand}`)

src/dev-environment.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,8 +2406,12 @@ export class DevEnvironment {
24062406
console.log(chalk.yellow(`🛑 Shutting down ${this.options.commandName} due to critical failure...`))
24072407
}
24082408

2409-
// Kill processes on both ports
2409+
// Kill processes on both ports (skip in sandbox - lsof doesn't exist)
24102410
const killPortProcess = async (port: string, name: string) => {
2411+
if (isInSandbox()) {
2412+
console.log(chalk.gray(`ℹ️ Skipping ${name} port kill in sandbox environment`))
2413+
return
2414+
}
24112415
try {
24122416
const { spawn } = await import("child_process")
24132417
const killProcess = spawn("sh", ["-c", `lsof -ti:${port} | xargs kill -9`], { stdio: "inherit" })
@@ -2605,8 +2609,13 @@ export class DevEnvironment {
26052609
// Now we keep .mcp.json, .cursor/mcp.json, and opencode.json configured
26062610
// for the next dev3000 run, providing a better developer experience
26072611

2608-
// Kill processes on both ports
2612+
// Kill processes on both ports (skip in sandbox - lsof doesn't exist)
26092613
const killPortProcess = async (port: string, name: string) => {
2614+
// Skip lsof-based kill in sandbox environments
2615+
if (isInSandbox()) {
2616+
this.debugLog(`Skipping ${name} port kill in sandbox environment`)
2617+
return
2618+
}
26102619
try {
26112620
const { spawn } = await import("child_process")
26122621

0 commit comments

Comments
 (0)