Skip to documentation
API + guides

01Documentation

Files

Read and manage persistent files without starting or resuming sandbox compute. The existing Files API and SDK methods support reading, writing, listing, stat, directory creation, moving, and deletion while a sandbox is paused.

Files belong to the sandbox identity and survive successful checkpointed pause/resume. Deleting the sandbox removes its current filesystem; create a snapshot or fork first when you need a reusable copy.

Access While Paused#

No new endpoint, flag, or SDK is required. Offline access uses platform storage workers and storage services while the sandbox's guest compute remains stopped; it does not execute guest commands. File operations do not trigger auto_resume, including when it is enabled, and work when auto_resume is disabled.

Sandbox stateFile operations
RunningRead and modify the current guest filesystem.
Filesystem-only pauseRead, write, stat, list, mkdir, move, and delete persistent files without resuming compute. Successful changes are durable and visible on the next resume.
Memory pauseRead, stat, and list the committed RootFS without resuming. Writes, mkdir, move, and delete return 409 conflict to preserve the retained process state.
Lifecycle transitionRequests can wait for the current operation or return a conflict/unavailable response. They never start compute to work around a conflict.

To edit files while preserving a memory checkpoint's processes, explicitly resume with memory first. File access never silently drops a memory checkpoint or switches to a fresh process launch.

Offline access covers the persistent RootFS. Virtual filesystems and runtime mounts, such as /tmp, /proc, /sys, /dev, managed credentials, and template tmpfs mounts, require the runtime and are unavailable offline. Offline operations reject these paths, including aliases through symlinks; directories containing runtime mounts cannot be moved or deleted offline. SSH/SFTP and file watching also require running compute; watch keeps its existing auto_resume behavior.

Use a handle for an existing sandbox; creating the handle does not claim or resume compute:

go
sandbox := client.Sandbox("sb_abc123") entries, err := sandbox.ListFiles(ctx, "/workspace") if err != nil { log.Fatal(err) } content, err := sandbox.ReadFile(ctx, "/workspace/output.txt") if err != nil { log.Fatal(err) } // During a filesystem-only pause, this persists without resuming compute. _, err = sandbox.WriteFile(ctx, "/workspace/input.txt", []byte("next task")) if err != nil { log.Fatal(err) } fmt.Printf("Listed %d entries; read %d bytes\n", len(entries), len(content))

Offline writes publish a new immutable filesystem generation before returning success. They serialize with resume, restore, snapshots, deletion, and other writes. A failed operation does not publish its partial changes. If a connection is lost, the mutation outcome may be uncertain: inspect the file or directory before retrying a move, delete, or write. A write replaces one file atomically; several API calls are separate operations.

File Model#

FileInfo#

FieldTypeDescription
namestringFile name
pathstringRequested path, or a directory entry path beneath it; use absolute paths for unambiguous results
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 and missing parent directories if needed, or atomically replaces the existing file. Each call writes the complete new content; it does not append.

POST

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

Query Parameters#

ParameterTypeDescription
pathstringFile path to write (required)

Request Body#

Binary file content (raw bytes), up to 100 MiB. The limit is the same for running and paused sandboxes.

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
// Recreate the sample file after the earlier move/delete examples. if _, err := sandbox.WriteFile(ctx, "/workspace/hello.txt", []byte("Hello from Sandbox0!\n")); err != nil { log.Fatal(err) } // 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. Watching requires a running sandbox and can resume compute when auto_resume is enabled. Offline reads and edits do not provide a watch stream.

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 { errs = nil continue } if err != nil { log.Printf("Watch error: %v", err) } case <-watchCtx.Done(): fmt.Println("Watch timeout") return } }

Next Steps#