Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:OpenHands OpenHands E2BFileStore

From Leeroopedia
Knowledge Sources
Domains Cloud_Infrastructure, Runtime_Management
Last Updated 2026-02-11 21:00 GMT

Overview

Concrete wrapper for performing file operations inside an E2B cloud sandbox, provided by the OpenHands third-party runtime layer.

Description

E2BFileStore is an adapter class that implements the FileStore abstract interface by delegating to the E2B SDK's native filesystem API. It wraps an E2B sandbox instance and translates the four standard file operations (write, read, list, delete) into corresponding E2B SDK calls.

Unlike the Daytona, Modal, and Runloop runtimes (which delegate file operations to the action execution server via HTTP endpoints), E2BFileStore provides direct filesystem access through the E2B SDK. This eliminates the HTTP overhead and allows for lower-latency file operations within E2B sandboxes.

The class is initialized during E2BRuntime.connect() and is stored as an attribute on the runtime instance. All file operations on E2BRuntime are routed through this FileStore implementation.

Note: Daytona, Modal, and Runloop runtimes do not use E2BFileStore. They inherit file transfer capabilities from ActionExecutionClient, which uses the action server's /upload_file and /download_file HTTP endpoints for file I/O, and shell commands via /execute_action for listing and deletion.

Usage

Use E2BFileStore to read, write, list, or delete files inside an E2B sandbox. In practice, the E2BRuntime creates and manages this object internally; external code interacts with it through the runtime's file operation methods.

Code Reference

Source Location

  • Repository: OpenHands
  • File: third_party/runtime/impl/e2b/filestore.py
  • Lines: L13-27

Signature

class E2BFileStore(FileStore):
    def __init__(self, sandbox):
        self.sandbox = sandbox

    def write(self, path: str, contents: str) -> None:
        ...

    def read(self, path: str) -> str:
        ...

    def list(self, path: str) -> list[str]:
        ...

    def delete(self, path: str) -> None:
        ...

Import

from third_party.runtime.impl.e2b.filestore import E2BFileStore

I/O Contract

Inputs

Constructor

Name Type Required Description
sandbox E2BSandbox Yes An active E2B sandbox instance with filesystem API access

write()

Name Type Required Description
path str Yes Absolute path inside the sandbox where the file should be written
contents str Yes String contents to write to the file

read()

Name Type Required Description
path str Yes Absolute path inside the sandbox of the file to read

list()

Name Type Required Description
path str Yes Absolute path inside the sandbox of the directory to list

delete()

Name Type Required Description
path str Yes Absolute path inside the sandbox of the file or directory to delete

Outputs

Name Type Description
write() None Returns None on success; raises an exception on failure
read() str Returns the string contents of the file at the given path
list() list[str] Returns a list of filenames and directory names at the given path
delete() None Returns None on success; raises an exception on failure

Usage Examples

Basic Usage

from third_party.runtime.impl.e2b.filestore import E2BFileStore

# Typically created internally by E2BRuntime during connect():
filestore = E2BFileStore(sandbox=e2b_sandbox)

# Write a file:
filestore.write("/workspace/config.json", '{"key": "value"}')

# Read a file:
contents = filestore.read("/workspace/config.json")
print(contents)  # '{"key": "value"}'

# List directory contents:
files = filestore.list("/workspace")
print(files)  # ['config.json', 'src', 'tests']

# Delete a file:
filestore.delete("/workspace/config.json")

Through E2BRuntime

from third_party.runtime.impl.e2b.e2b_runtime import E2BRuntime

runtime = E2BRuntime(config=openhands_config, event_stream=event_stream)
await runtime.connect()

# The runtime's filestore is available after connect():
runtime.filestore.write("/workspace/hello.py", "print('Hello, world!')")
contents = runtime.filestore.read("/workspace/hello.py")

Related Pages

Implements Principle

Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment