firecrawl/open-lovable · error · Error
Failed to list files
Error message
Failed to list files
What it means
Thrown by GET /api/get-sandbox-files when a `find` command run inside the sandbox exits non-zero while enumerating project files. The stderr is not captured, so the actual cause (missing directory, find unavailable, permission denied) must be inferred or checked in the sandbox.
Solutions
- Run the find command manually in the sandbox to see stderr (the route discards it, so add stderr logging first)
- Verify the project directory exists in the sandbox before listing; recreate the sandbox and re-apply code if it was reset
- Capture stderr in the error message for diagnosability
- Add a fallback listing method (e.g. `ls -R` or the SDK's files.list API) if find is unavailable
Example fix
// before
if (findResult.exitCode !== 0) {
throw new Error('Failed to list files');
}
// after
if (findResult.exitCode !== 0) {
const errText = await findResult.stderr();
throw new Error(`Failed to list files: exit ${findResult.exitCode}: ${errText}`);
} Defensive patterns
Strategy: try-catch
Validate before calling
const dirExists = await sandbox.runCommand({ cmd: 'bash', args: ['-c', 'test -d /project && echo yes || echo no'] });
if ((await dirExists.stdout()).trim() !== 'yes') throw new Error('Project directory missing in sandbox — recreate sandbox'); Type guard
function commandOk(r: { exitCode: number }): boolean { return r.exitCode === 0; } Try / catch
try {
const files = await getSandboxFiles();
} catch (e) {
if (e.message === 'Failed to list files') {
await recreateSandboxAndReapplyCode();
return getSandboxFiles();
}
throw e;
} Prevention
- Capture stderr in the error message so the real cause is visible
- Check directory existence before running find
- Recreate and re-provision the sandbox after restarts — /tmp and project dirs are ephemeral
- Add a health check endpoint that verifies the sandbox filesystem before file operations
When it happens
Trigger: GET /api/get-sandbox-files where the in-sandbox `find` over the project directory fails: the project directory no longer exists (sandbox restarted/reset), the find binary is missing, or the command exceeded args/resources.
Common situations: Sandbox timed out and was recreated, losing the project directory; working directory path changed between app versions; extremely large trees making the command slow until the client aborts.
Related errors
- Failed to create zip
- Failed to read file
- Failed to read zip file
- Failed to write file via command
- Failed to write file via shell
AI-assisted analysis of firecrawl/open-lovable@69bd93bae7 (2026-08-28).
Data as JSON: /api/errors/324ca5a5c5e68bf0.
Report an issue: GitHub.
Appendix: source
Thrown at app/api/get-sandbox-files/route.ts:44
'-name', 'node_modules', '-prune', '-o',
'-name', '.git', '-prune', '-o',
'-name', 'dist', '-prune', '-o',
'-name', 'build', '-prune', '-o',
'-type', 'f',
'(',
'-name', '*.jsx',
'-o', '-name', '*.js',
'-o', '-name', '*.tsx',
'-o', '-name', '*.ts',
'-o', '-name', '*.css',
'-o', '-name', '*.json',
')',
'-print'
]
});
if (findResult.exitCode !== 0) {
throw new Error('Failed to list files');
}
const fileList = (await findResult.stdout()).split('\n').filter((f: string) => f.trim());
console.log('[get-sandbox-files] Found', fileList.length, 'files');
// Read content of each file (limit to reasonable sizes)
const filesContent: Record<string, string> = {};
for (const filePath of fileList) {
try {
// Check file size first
const statResult = await global.activeSandbox.runCommand({
cmd: 'stat',
args: ['-f', '%z', filePath]
});
if (statResult.exitCode === 0) {
const fileSize = parseInt(await statResult.stdout());View on GitHub (pinned to 69bd93bae7)