@papercraneai/sandbox-agent 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +21 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { createServer } from "http";
4
4
  import { WebSocketServer, WebSocket } from "ws";
5
5
  import { Tail } from "tail";
6
6
  import { query, tool, createSdkMcpServer } from "@anthropic-ai/claude-agent-sdk";
7
- import { readdir, stat, mkdir, readFile, writeFile, access, unlink } from "fs/promises";
7
+ import { readdir, stat, mkdir, readFile, writeFile, access, unlink, rm } from "fs/promises";
8
8
  import { join, dirname, resolve } from "path";
9
9
  import { fileURLToPath } from "url";
10
10
  import { spawn, execSync } from "child_process";
@@ -837,13 +837,17 @@ app.delete("/files/delete", async (req, res) => {
837
837
  res.status(403).json({ error: "Access denied: path outside project directory" });
838
838
  return;
839
839
  }
840
- // Check if file exists and is not a directory
840
+ // Prevent deleting the project root itself
841
+ if (resolvedPath === resolvedProject) {
842
+ res.status(400).json({ error: "Cannot delete the project root directory" });
843
+ return;
844
+ }
845
+ const recursive = req.query.recursive === "true" || req.body?.recursive === true;
846
+ // Check if path exists
847
+ let isDirectory = false;
841
848
  try {
842
849
  const stats = await stat(fullPath);
843
- if (stats.isDirectory()) {
844
- res.status(400).json({ error: "Cannot delete a directory, only files", path: sanitizedPath });
845
- return;
846
- }
850
+ isDirectory = stats.isDirectory();
847
851
  }
848
852
  catch (error) {
849
853
  if (error.code === "ENOENT") {
@@ -852,8 +856,17 @@ app.delete("/files/delete", async (req, res) => {
852
856
  }
853
857
  throw error;
854
858
  }
855
- // Delete the file
856
- await unlink(fullPath);
859
+ if (isDirectory && !recursive) {
860
+ res.status(400).json({ error: "Cannot delete a directory without recursive flag", path: sanitizedPath });
861
+ return;
862
+ }
863
+ // Delete file or directory
864
+ if (isDirectory) {
865
+ await rm(fullPath, { recursive: true });
866
+ }
867
+ else {
868
+ await unlink(fullPath);
869
+ }
857
870
  log.info({ path: sanitizedPath }, "File deleted");
858
871
  res.json({
859
872
  success: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@papercraneai/sandbox-agent",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Claude Agent SDK server for sandbox environments",
5
5
  "license": "MIT",
6
6
  "type": "module",