Persist Outputs
Interactive sessions are useful for discovery, but the container filesystem is not the right long-term storage layer. Save anything important before stopping or replacing the service run.
This page continues from the Sandbox Quick Start. The Python examples reuse its sandbox client; the CLI examples reuse its quick-start project, /workspace directory, and RUN_UUID variable.
Persist Artifacts
Write generated files to the run's outputs path and log them with the tracking library:
from pathlib import Path
from polyaxon import tracking
from polyaxon.schemas import V1ArtifactKind
tracking.init()
report_path = tracking.get_outputs_path("reports/evaluation.json")
Path(report_path).write_text('{"accuracy": 0.91}\n', encoding="utf-8")
tracking.log_artifact_ref(
path=report_path,
kind=V1ArtifactKind.FILE,
name="evaluation-report",
)get_outputs_path() writes into the run's synced outputs directory. log_artifact_ref() records artifact metadata; it does not copy an arbitrary file into the artifact store.
This code runs inside the service container and requires the Polyaxon tracking library in its image. The host-side SandboxClient examples below control that container remotely.
See tracking artifacts for artifact logging patterns.
Download Scratch Files
Use sandbox file transfer when a file is still in /workspace rather than the synced outputs directory. This example uploads and runs the profile fixture before downloading its output:
sandbox.fs.upload_file(
local_path="./sandbox/profile.py",
path="/workspace/profile.py",
)
result = sandbox.process.exec(
command=["python", "/workspace/profile.py"],
)
print(result.stdout, end="")
sandbox.fs.download_file(
path="/workspace/profile.json",
local_path="./sandbox/profile.downloaded.json",
)polyaxon sandbox upload -p quick-start -uid $RUN_UUID \
./sandbox/profile.py /workspace/profile.py
polyaxon sandbox exec -p quick-start -uid $RUN_UUID -- python /workspace/profile.py
polyaxon sandbox download -p quick-start -uid $RUN_UUID \
/workspace/profile.json ./sandbox/profile.downloaded.jsonCommit Code Changes
If the sandbox produced code changes that should live beyond the session, push them to a Git branch using a scoped credential:
status = sandbox.process.exec(
command=["git", "-C", "/workspace/repo", "status"],
)
print(status.stdout, end="")
push = sandbox.process.exec(
command=["git", "-C", "/workspace/repo", "push", "origin", "HEAD"],
timeout_ms=120_000,
)
print(push.stdout, end="")
print(push.stderr, end="")polyaxon sandbox exec -p quick-start -uid $RUN_UUID -- git -C /workspace/repo status
polyaxon sandbox exec -p quick-start -uid $RUN_UUID -- git -C /workspace/repo push origin HEADPreserve Reproducibility
When a manual session discovers a useful fix, move the change into a reproducible place:
- Source code in Git.
- Dependencies in an image or lockfile.
- Runtime settings in a Polyaxonfile or preset.
- Results in artifacts, metrics, or model registry entries.
See the Python process and filesystem references, or the sandbox CLI reference, for the full interfaces.