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

Function executeFile

scripts/sparc2/src/sandbox/codeInterpreter.ts:210–254  ·  view source on GitHub ↗
(
  filePath: string,
  options: {
    stream?: boolean;
    language?: "python" | "javascript" | "typescript";
    timeout?: number;
  } = {},
)

Source from the content-addressed store, hash-verified

208 * @returns The execution result
209 */
210export async function executeFile(
211 filePath: string,
212 options: {
213 stream?: boolean;
214 language?: "python" | "javascript" | "typescript";
215 timeout?: number;
216 } = {},
217): Promise<ExecutionResult> {
218 try {
219 // Read the file content
220 const content = await Deno.readTextFile(filePath);
221
222 // Determine language from file extension if not specified
223 if (!options.language) {
224 const extension = filePath.split(".").pop()?.toLowerCase();
225 if (extension === "py") {
226 options.language = "python";
227 } else if (extension === "js") {
228 options.language = "javascript";
229 } else if (extension === "ts") {
230 options.language = "typescript";
231 }
232 }
233
234 // Execute the file content
235 return await executeCode(content, options);
236 } catch (error: unknown) {
237 const errorMessage = error instanceof Error ? error.message : String(error);
238 await logMessage("error", `Failed to execute file: ${filePath}`, { error: errorMessage });
239
240 // Return an error result
241 return {
242 text: "",
243 results: [],
244 error: {
245 type: "error",
246 value: errorMessage,
247 },
248 logs: {
249 stdout: [],
250 stderr: [errorMessage],
251 },
252 };
253 }
254}
255
256/**
257 * Write a file in the sandbox

Callers 1

runSWEBenchFunction · 0.90

Calls 2

logMessageFunction · 0.90
executeCodeFunction · 0.70

Tested by

no test coverage detected