(path: string)
| 189 | * @returns The file content |
| 190 | */ |
| 191 | export async function readFile(path: string): Promise<string> { |
| 192 | const sandbox = await createSandbox(); |
| 193 | |
| 194 | try { |
| 195 | const content = await sandbox.filesystem.read(path); |
| 196 | await logMessage("info", `File read from sandbox: ${path}`, { contentLength: content.length }); |
| 197 | return content; |
| 198 | } catch (error: unknown) { |
| 199 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 200 | await logMessage("error", `Failed to read file from sandbox: ${path}`, { error: errorMessage }); |
| 201 | throw error; |
| 202 | } finally { |
| 203 | await sandbox.close(); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * List files in the sandbox |
no test coverage detected