Skip to content

Python Commands and Files

AsyncRunta and Runta use the same runtime command and file helper names. Async examples await I/O operations; sync examples call the same methods directly.

InterfacePurpose
runtime.exec(command, …)Run a buffered command and return exit code, stdout, and stderr.
runtime.exec_detached(command, …)Start command execution from the SDK process and await the task later.

Run a shell command:

result = await runtime.exec("pwd && ls -la", timeout=30)
print(result.exit_code)
print(result.stdout_text)
print(result.stderr_text)

Run an argv-style command:

result = await runtime.exec(["python3", "--version"])

Pass environment variables, stdin, working directory, timeout, and output limits:

result = await runtime.exec(
["sh", "-lc", "cat input.txt && echo $APP_ENV"],
cwd="/workspace",
env={"APP_ENV": "dev"},
stdin="hello\n",
timeout=30,
max_output_bytes=1024 * 1024,
)

Run in the background from the SDK process:

task = runtime.exec_detached("sleep 5 && echo done")
result = await task
InterfacePurpose
runtime.files.write(path, data)Write bytes or text to one runtime file.
runtime.files.read(path)Read one runtime file as bytes.
runtime.files.upload(local, remote)Upload one file or directory.
runtime.files.download(remote, local)Download one file or directory.
await runtime.files.write("/tmp/message.txt", "hello")
print((await runtime.files.read("/tmp/message.txt")).decode())
await runtime.files.upload("./local-file.txt", "/tmp/local-file.txt")
await runtime.files.download("/tmp/local-file.txt", "./downloaded-file.txt")

Python read() returns bytes. Directory upload support is implemented by the SDK on top of the file routes and runtime command execution.