Lines 691-731javascript
693 async readFile(sandboxId, path) {
695 const result = await this.exec(sandboxId, `cat ${this.shellEscape(path)}`);
696 const execResult = result;
697 if (execResult.exit_code !== 0) {
698 throw new Error(execResult.stderr || `cat exited with code ${execResult.exit_code}`);
700 return execResult.stdout;
702 if (err instanceof ProviderError)
704 throw new ProviderError("modal", `Failed to read file ${path}: ${err.message}`);
707 async writeFile(sandboxId, path, content) {
709 const encoded = Buffer.from(content).toString("base64");
710 const dirPath = path.substring(0, path.lastIndexOf("/")) || "/";
711 const cmd = `mkdir -p ${this.shellEscape(dirPath)} && echo ${encoded} | base64 -d > ${this.shellEscape(path)}`;
712 const result = await this.exec(sandboxId, `sh -c ${this.shellEscape(cmd)}`);
713 const execResult = result;
714 if (execResult.exit_code !== 0) {
715 throw new Error(execResult.stderr || `write exited with code ${execResult.exit_code}`);
718 if (err instanceof ProviderError)
720 throw new ProviderError("modal", `Failed to write file ${path}: ${err.message}`);
723 async listFiles(sandboxId, path) {
725 const result = await this.exec(sandboxId, `ls -la ${this.shellEscape(path)}`);
726 const execResult = result;
727 if (execResult.exit_code !== 0) {
728 throw new Error(execResult.stderr || `ls exited with code ${execResult.exit_code}`);
730 const lines = execResult.stdout.split(`
731`).filter((l) => l.trim());