Guide
Transfer files
Move data into and out of a sandbox without rebuilding the disk image. Use the portal to browse and download, or use CLI and SDK calls for write access.
Write and read a file
CLI/SDK only for writes
The portal Files view is read-only. Use the CLI or SDK to write files, then use the portal to browse, preview, or download them.
- 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
CLI/SDK only
The portal file explorer does not create, upload, or delete files. Use the interactive shell, CLI, or SDK when you need to change the sandbox file system.
- 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)