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

Function executeFile

scripts/e2b/e2b-code-interpreter.ts:183–223  ·  view source on GitHub ↗
(
  filePath: string,
  options: RunCodeOptions = {}
)

Source from the content-addressed store, hash-verified

181 * @returns The execution result
182 */
183export async function executeFile(
184 filePath: string,
185 options: RunCodeOptions = {}
186): Promise<ExecutionResult> {
187 try {
188 // Read the file content
189 const content = await Deno.readTextFile(filePath);
190
191 // Determine language from file extension if not specified
192 if (!options.language) {
193 const extension = filePath.split('.').pop()?.toLowerCase();
194 if (extension === 'py') {
195 options.language = 'python';
196 } else if (extension === 'js') {
197 options.language = 'javascript';
198 } else if (extension === 'ts') {
199 options.language = 'typescript';
200 }
201 }
202
203 // Execute the file content
204 return await executeCode(content, options);
205 } catch (error: unknown) {
206 const errorMessage = error instanceof Error ? error.message : String(error);
207 console.error(`Failed to execute file: ${filePath}`, errorMessage);
208
209 // Return an error result
210 return {
211 text: "",
212 results: [],
213 error: {
214 type: "error",
215 value: errorMessage
216 },
217 logs: {
218 stdout: [],
219 stderr: [errorMessage]
220 }
221 };
222 }
223}
224
225/**
226 * Write a file in the sandbox

Callers

nothing calls this directly

Calls 1

executeCodeFunction · 0.70

Tested by

no test coverage detected