Skip to content

Add agent-server endpoint for archiving workspace files #3779

@neubig

Description

@neubig

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

  1. Add an endpoint such as GET /file/archive?path=/workspace/project.
  2. Return a streamed .zip or .tar.gz archive of the requested directory.
  3. Validate that the requested path is absolute, exists, and is a directory.
  4. Prevent path traversal and avoid following symlinks outside the requested root.
  5. Prefer streaming or temp-file cleanup via BackgroundTask so large workspaces do not remain on disk after response completion.
  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions