MCPcopy Create free account
hub / github.com/agenticsorg/edge-agents / readFile

Function readFile

scripts/sparc2/src/sandbox/codeInterpreter.ts:292–314  ·  view source on GitHub ↗
(
  path: string,
  options: CodeInterpreterOptions = {},
  existingSandbox?: Sandbox,
)

Source from the content-addressed store, hash-verified

290 * @returns The file content
291 */
292export async function readFile(
293 path: string,
294 options: CodeInterpreterOptions = {},
295 existingSandbox?: Sandbox,
296): Promise<string> {
297 const sandbox = existingSandbox || await createSandbox(options);
298
299 try {
300 // @ts-ignore - Ignore TypeScript errors for API compatibility
301 const content = await sandbox.files.read(path);
302 await logMessage("info", `File read from sandbox: ${path}`, { contentLength: content.length });
303 return content;
304 } catch (error: unknown) {
305 const errorMessage = error instanceof Error ? error.message : String(error);
306 await logMessage("error", `Failed to read file from sandbox: ${path}`, { error: errorMessage });
307 throw error;
308 } finally {
309 if (!existingSandbox) {
310 // @ts-ignore - Ignore TypeScript errors for API compatibility
311 await sandbox.kill();
312 }
313 }
314}
315
316/**
317 * List files in the sandbox

Callers 1

fnFunction · 0.90

Calls 2

logMessageFunction · 0.90
createSandboxFunction · 0.70

Tested by 1

fnFunction · 0.72