SANDBOX/Files

#Files

Manage files and directories within a sandbox. The Files API provides full POSIX file operations including read, write, delete, move, and real-time file watching.

Files written to the sandbox writable filesystem are restored across checkpointed pause/resume for the same sandbox identity, including paths that are not backed by mounted Volumes. They are deleted with the sandbox identity unless you publish a rootfs snapshot or fork before cleanup. Use Snapshot And Restore for sandbox rootfs checkpoints, restore, and fork operations. Use Volumes for data that must be shared across sandboxes or accessed directly without a running sandbox.

File Model#

FileInfo#

FieldTypeDescription
namestringFile name
pathstringFull path
typestringFile type: file, dir, symlink
sizeintegerFile size in bytes
modestringUnix file mode (e.g., 0755)
mod_timestringLast modification time (ISO 8601)
is_linkbooleanWhether it's a symlink
link_targetstringSymlink target path (if applicable)

Write File#

Write content to a file. Creates the file if it doesn't exist.

POST

/api/v1/sandboxes/{id}/files

Query Parameters#

ParameterTypeDescription
pathstringFile path to write (required)

Request Body#

Binary file content (raw bytes).

go
// Write file content content := []byte("Hello from Sandbox0!\n") _, err := sandbox.WriteFile(ctx, "/workspace/hello.txt", content) if err != nil { log.Fatal(err) } fmt.Println("File written successfully")

Read File#

Read file content from a sandbox.

GET

/api/v1/sandboxes/{id}/files

Query Parameters#

ParameterTypeDescription
pathstringFile path to read (required)
go
// Read the file readResult, err := sandbox.ReadFile(ctx, "/workspace/hello.txt") if err != nil { log.Fatal(err) } fmt.Printf("File content: %s\n", strings.TrimSpace(string(readResult)))

Create Directory#

Create a new directory.

POST

/api/v1/sandboxes/{id}/files

Query Parameters#

ParameterTypeDescription
pathstringDirectory path to create (required)
mkdirbooleanSet to true to create directory
recursivebooleanCreate parent directories if needed
go
// Create directory (with parent directories) _, err = sandbox.Mkdir(ctx, "/workspace/project/src", true) if err != nil { log.Fatal(err) } fmt.Println("Directory created")

Move File or Directory#

Move or rename a file or directory.

POST

/api/v1/sandboxes/{id}/files/move

Request Body#

FieldTypeDescription
sourcestringSource path
destinationstringDestination path
go
// Move/rename file _, err = sandbox.MoveFile(ctx, "/workspace/hello.txt", "/workspace/new-hello.txt") if err != nil { log.Fatal(err) } fmt.Println("File moved")

Delete File or Directory#

Delete a file or directory.

DELETE

/api/v1/sandboxes/{id}/files

Query Parameters#

ParameterTypeDescription
pathstringPath to delete (required)

Deleting a directory removes all its contents recursively. This action cannot be undone.

go
// Delete file _, err = sandbox.DeleteFile(ctx, "/workspace/new-hello.txt") if err != nil { log.Fatal(err) } fmt.Println("File deleted")

Get File Info (Stat)#

Get metadata about a file or directory.

GET

/api/v1/sandboxes/{id}/files/stat

Query Parameters#

ParameterTypeDescription
pathstringFile path to stat (required)
go
// Get file info info, err := sandbox.StatFile(ctx, "/workspace/hello.txt") if err != nil { log.Fatal(err) } if name, ok := info.Name.Get(); ok { fmt.Printf("Name: %s\n", name) } if size, ok := info.Size.Get(); ok { fmt.Printf("Size: %d bytes\n", size) } if fileType, ok := info.Type.Get(); ok { fmt.Printf("Type: %s\n", fileType) } if mode, ok := info.Mode.Get(); ok { fmt.Printf("Mode: %s\n", mode) }

List Directory#

List contents of a directory.

GET

/api/v1/sandboxes/{id}/files/list

Query Parameters#

ParameterTypeDescription
pathstringDirectory path to list (required)
go
// List directory contents entries, err := sandbox.ListFiles(ctx, "/workspace") if err != nil { log.Fatal(err) } for _, entry := range entries { path, ok := entry.Path.Get() if !ok { continue } fileType, _ := entry.Type.Get() size, _ := entry.Size.Get() fmt.Printf("- %s (%s, %d bytes)\n", path, fileType, size) }

Watch Files#

Watch a directory for file system changes in real-time via WebSocket.

GET

/api/v1/sandboxes/{id}/files/watch

WebSocket Protocol#

Client Messages:

ActionDescriptionExample
subscribeSubscribe to a path{"action": "subscribe", "path": "/tmp", "recursive": true}
unsubscribeUnsubscribe from a watch{"action": "unsubscribe", "watch_id": "watch-123"}

Server Messages:

TypeDescriptionExample
subscribedSubscription confirmed{"type": "subscribed", "watch_id": "watch-123", "path": "/tmp"}
eventFile event occurred{"type": "event", "watch_id": "watch-123", "event": "write", "path": "/tmp/a.txt"}
unsubscribedUnsubscription confirmed{"type": "unsubscribed", "watch_id": "watch-123"}
errorError occurred{"type": "error", "error": "permission denied"}

File Events#

EventDescription
createFile or directory created
writeFile content modified
renameFile or directory renamed
chmodFile permissions changed
removeFile or directory deleted
go
// Watch files for changes watchCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() events, errs, unsubscribe, err := sandbox.WatchFiles(watchCtx, "/workspace", true) if err != nil { log.Fatal(err) } defer func() { if err := unsubscribe(); err != nil { log.Printf("cleanup unsubscribe watch: %v", err) } }() // Process events for { select { case ev, ok := <-events: if !ok { return } fmt.Printf("Event: %s on %s\n", ev.Event, ev.Path) case err, ok := <-errs: if ok && err != nil { log.Printf("Watch error: %v", err) } case <-watchCtx.Done(): fmt.Println("Watch timeout") return } }

Next Steps#

SSH

Connect to sandboxes with standard SSH clients for shell and file-copy workflows.

Network

Configure outbound network policy, traffic rules, and protocol-aware restrictions.