Foundational Compute

Files

Move files in and out with the SDK, fdtn cp or fdtn collect.

Write and read a file

Python · TypeScript · CLI

files.py
from fdtn import Sandbox

sbx = Sandbox.create("base")
sbx.files.write("/home/user/data/in.txt", "3\n1\n2\n")
sbx.commands.run("sort /home/user/data/in.txt > /home/user/data/out.txt")
print(sbx.files.read("/home/user/data/out.txt"))   # 1 2 3
sbx.kill()

A write creates missing parent folders and replaces an existing file.

Files are deleted when the sandbox ends.

SDK file methods

A relative path starts at the home folder.

TaskPythonTypeScript
Write one filewrite(path, data)write(path, data)
Write many fileswrite_files([...])write([...])
Read a fileread(path, format=...)read(path, { format })
List a folderlist(path, depth=1)list(path, { depth })
Check a pathexists(path)exists(path)
File detailsget_info(path)getInfo(path)
Make a foldermake_dir(path)makeDir(path)
Move or renamerename(old, new)rename(old, new)
Remove (with contents)remove(path)remove(path)
Watch a folderwatch_dir(path)watchDir(path, onEvent)

Each method also takes user. See Python, TypeScript.

Write data

An open file or a Blob uploads in pieces.

Python · TypeScript

# text and bytes
sbx.files.write("/app/config.json", '{"debug": true}')
sbx.files.write("/app/logo.png", open("logo.png", "rb").read())

# a large local file, sent in pieces
with open("dataset.csv", "rb") as f:
    sbx.files.write("/app/dataset.csv", f)

# many files in one call
sbx.files.write_files([
    {"path": "/app/a.py", "data": "print('a')"},
    {"path": "/app/b.py", "data": "print('b')"},
])

Read data

Reads return text. Use bytes for binary, stream for large files.

Python · TypeScript

text = sbx.files.read("/app/out.txt")
image = sbx.files.read("/app/chart.png", format="bytes")

with open("big.tar", "wb") as f:
    for chunk in sbx.files.read("/app/big.tar", format="stream"):
        f.write(chunk)

fdtn cp

Write the sandbox side as <id>:/path or @name:/path.

$ fdtn cp ./input.json @worker:/app/input.json        # upload one file
$ fdtn cp -r ./src @worker:/app/src                   # upload a folder
$ fdtn cp -r @worker:/app/results ./results           # download a folder
$ fdtn cp --force @worker:/app/out.txt ./out.txt      # replace
  • Without --force, the copy stops at the first file that exists.
  • A folder copy puts its contents into the destination folder.
  • The copy stops at a symbolic link. On macOS, write /private/tmp, not /tmp.
  • A copy to or from a paused sandbox resumes it.
  • For a local path with a colon, use fdtn files.

fdtn files

ls, pull, push, info, mkdir, move, remove. CLI

Collect from many sandboxes

fdtn collect downloads one folder from each sandbox with the given metadata, into a local folder per sandbox ID. manifest.json holds a SHA-256 checksum per file.

$ fdtn collect --metadata run=eval-1 --path /app/results --destination ./results-1
  • --destination must not exist (else EEXIST).
  • Paused sandboxes resume for the download.
  • On exit code 1, run fdtn collect --retry-failed --destination ./results-1 to retry only the failed sandboxes.

Full flow: Many sandboxes.

Size limits

Free disk is 5, 10 or 20 GiB by template memory, at no charge (sizes). Put large shared inputs in a template.

Next