Guide
Transfer files
Move data into and out of a sandbox without rebuilding the disk image. Use the portal to browse files, create folders, and delete paths, or use CLI and SDK calls for broader write access.
Write and read a file
Portal file actions
The portal Files view can browse directories, create folders, and delete files or directories. Use the terminal, CLI, or SDK for other file writes.
- Open the sandbox from Sandbox groups > your group > Sandboxes.
- Go to the Files view.
- Browse to the directory that contains the file.
- Bash
- PowerShell
- SDK
printf 'Hello from the CLI!' > aca-sample-hello.txt
aca sandbox fs write -l name=demo-files \
--path /tmp/hello.txt \
--file aca-sample-hello.txt
aca sandbox fs cat -l name=demo-files --path /tmp/hello.txt
'Hello from the CLI!' | Set-Content -NoNewline aca-sample-hello.txt
aca sandbox fs write -l name=demo-files `
--path /tmp/hello.txt `
--file aca-sample-hello.txt
aca sandbox fs cat -l name=demo-files --path /tmp/hello.txt
import os
from azure.identity import DefaultAzureCredential
from azure.containerapps.sandbox import SandboxGroupClient, endpoint_for_region
credential = DefaultAzureCredential()
client = SandboxGroupClient(
endpoint_for_region(os.environ["ACA_SANDBOXGROUP_REGION"]),
credential,
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"],
resource_group=os.environ["ACA_RESOURCE_GROUP"],
sandbox_group=os.environ["ACA_SANDBOX_GROUP"],
)
sandbox = client.get_sandbox_client(os.environ["SANDBOX_ID"])
sandbox.write_file("/tmp/hello.txt", "Hello from the SDK!")
content = sandbox.read_file("/tmp/hello.txt")
print(content.decode())
Inspect and list files
Use metadata and directory listing calls when an agent writes output to a path you need to collect.
- Open the sandbox, then select Files.
- Select a folder to open it.
- Review the file names shown in the list.
- Bash
- PowerShell
- SDK
aca sandbox fs stat -l name=demo-files --path /tmp/hello.txt
aca sandbox fs ls -l name=demo-files --path /tmp
aca sandbox fs stat -l name=demo-files --path /tmp/hello.txt
aca sandbox fs ls -l name=demo-files --path /tmp
stat = sandbox.stat_file("/tmp/hello.txt")
print(stat.size, stat.is_directory)
listing = sandbox.list_files("/tmp")
entries = getattr(listing, "entries", listing)
for entry in entries:
kind = "DIR" if getattr(entry, "is_directory", False) else "FILE"
name = getattr(entry, "name", entry)
print(kind, name)
Create and delete paths
More file changes
The portal file explorer exposes folder creation and delete actions. Use the interactive shell, CLI, or SDK to upload content or make other file edits.
- Bash
- PowerShell
- SDK
aca sandbox fs mkdir -l name=demo-files --path /tmp/demo-dir
aca sandbox fs rm -l name=demo-files --path /tmp/hello.txt
aca sandbox fs rm -l name=demo-files --path /tmp/demo-dir --recursive
aca sandbox fs mkdir -l name=demo-files --path /tmp/demo-dir
aca sandbox fs rm -l name=demo-files --path /tmp/hello.txt
aca sandbox fs rm -l name=demo-files --path /tmp/demo-dir --recursive
sandbox.mkdir("/tmp/demo-dir")
sandbox.delete_file("/tmp/hello.txt")
sandbox.delete_file("/tmp/demo-dir", recursive=True)