Goal
Expose a safe agent-server endpoint that returns an archive of the active workspace files so callers can persist the agent's work before a runtime is deleted. In some cases we want to have a long-lived archive of the agent's work to prevent it from being irrecoverable.
Scope
Add or harden an endpoint in openhands-agent-server for downloading a directory archive.
Relevant code path:
openhands-agent-server/openhands/agent_server/file_router.py
- Existing
/file/upload and /file/download endpoints.
- Existing
_create_zip_from_directory() helper used for trajectory export.
Proposed implementation
- Add an endpoint such as
GET /file/archive?path=/workspace/project.
- Return a streamed
.zip or .tar.gz archive of the requested directory.
- Validate that the requested path is absolute, exists, and is a directory.
- Prevent path traversal and avoid following symlinks outside the requested root.
- Prefer streaming or temp-file cleanup via
BackgroundTask so large workspaces do not remain on disk after response completion.
- Add a manifest entry or deterministic archive metadata where practical.
Acceptance criteria
- A caller can request an archive of
/workspace/project and receive a valid archive.
- Requests for missing paths, files instead of directories, or unsafe paths fail with clear 4xx responses.
- Symlinks do not allow files outside the requested root to be included.
- Tests cover nested files, empty directories, unsafe symlinks, missing paths, and cleanup of temporary archive files.
- The endpoint is documented in the agent-server OpenAPI output.
Goal
Expose a safe agent-server endpoint that returns an archive of the active workspace files so callers can persist the agent's work before a runtime is deleted. In some cases we want to have a long-lived archive of the agent's work to prevent it from being irrecoverable.
Scope
Add or harden an endpoint in
openhands-agent-serverfor downloading a directory archive.Relevant code path:
openhands-agent-server/openhands/agent_server/file_router.py/file/uploadand/file/downloadendpoints._create_zip_from_directory()helper used for trajectory export.Proposed implementation
GET /file/archive?path=/workspace/project..zipor.tar.gzarchive of the requested directory.BackgroundTaskso large workspaces do not remain on disk after response completion.Acceptance criteria
/workspace/projectand receive a valid archive.