Skip to main content

A distributed, scalable filesystem backend for deep AI agents, backed by blob storage

Project description

Python Client Library

Python implementation of the agent-backend package. See the main README for an overview, quick start, and core usage.

Package Info

Field Value
Package agent-backend
Registry PyPI
Manager uv / pip
Test runner pytest
Build python -m build
Linter ruff
Type checker mypy
Source python/agent_backend/
Tests python/tests/

Advanced Features

Environment Variables

Scoped backends support custom environment variables that apply to all commands:

from agent_backend import ScopeConfig

scoped_backend = backend.scope("projects/my-app", ScopeConfig(
    env={
        "PYTHONPATH": "/workspace/lib",
        "API_KEY": "secret",
        "DATABASE_URL": "postgres://...",
    }
))

await scoped_backend.exec("python -m build")  # uses custom env

Operations Logging

from agent_backend import ConsoleOperationsLogger, ScopeConfig

scoped_backend = backend.scope("project", ScopeConfig(
    operations_logger=ConsoleOperationsLogger()
))

await scoped_backend.exec("pip install -r requirements.txt")
# Logs: [AgentBackend] exec: pip install -r requirements.txt

Binary Data

from agent_backend import ReadOptions

image_data = await backend.read("logo.png", ReadOptions(encoding="buffer"))
tarball = await backend.exec("tar -czf - .", ExecOptions(encoding="buffer"))

Timeouts

from agent_backend import RemoteFilesystemBackend, RemoteFilesystemBackendConfig

backend = RemoteFilesystemBackend(RemoteFilesystemBackendConfig(
    root_dir="/tmp/agentbe-workspace",
    host="server.com",
    auth_token="...",
    operation_timeout_ms=300_000,  # 5 minutes
    max_output_length=10 * 1024 * 1024,  # 10MB
))

Backend Connection Pooling

See docs/connection-pooling.md for BackendPoolManager usage, key-based pooling, idle cleanup, and graceful shutdown.

Examples

Code Execution Sandbox

from agent_backend import LocalFilesystemBackend, LocalFilesystemBackendConfig, IsolationMode

sandbox = LocalFilesystemBackend(LocalFilesystemBackendConfig(
    root_dir="/tmp/agentbe-workspace",
    isolation=IsolationMode.AUTO,
))

user_code_backend = sandbox.scope(f"users/{user_id}")
await user_code_backend.write("script.py", untrusted_code)
result = await user_code_backend.exec("python script.py")

Multi-tenant SaaS

from agent_backend import RemoteFilesystemBackend, RemoteFilesystemBackendConfig

# Separate backend per organization
org1_backend = RemoteFilesystemBackend(RemoteFilesystemBackendConfig(
    root_dir="/var/saas/org1",
    host="org1-server.example.com",
    auth_token="...",
))

org2_backend = RemoteFilesystemBackend(RemoteFilesystemBackendConfig(
    root_dir="/var/saas/org2",
    host="org2-server.example.com",
    auth_token="...",
))

# Scoped backends per user within each org
org1_user1 = org1_backend.scope("users/user1")
org1_user2 = org1_backend.scope("users/user2")

Agent State Management

from agent_backend import MemoryBackend

state = MemoryBackend()

await state.write("agents/agent1/current-task", "building")
await state.write("agents/agent1/progress", "50%")

all_agents = await state.list_keys("agents/")

Error Handling

from agent_backend import BackendError, DangerousOperationError, PathEscapeError

try:
    await backend.exec("rm -rf /")
except DangerousOperationError as e:
    # Command blocked by safety validation
    print("Blocked:", e.operation)
except PathEscapeError:
    # Path attempted to escape scope
    pass
except BackendError as e:
    # General backend error (check e.code)
    print("Error:", e.code, str(e))

Development

Commands

All commands can be run from the monorepo root via Make or from the python/ directory via uv.

Task Make (root) uv (python/)
Build make build-python uv build
Test make test-python uv run pytest
Test (cov) -- uv run pytest --cov=agent_backend --cov-fail-under=80
Lint make lint-python uv run ruff check .
Lint (fix) make lint-fix uv run ruff check --fix .
Typecheck make typecheck-python uv run ty check

Code Style

  • ruff enforces formatting (line-length = 100, target-version = "py311")
  • Type hints on all function signatures -- avoid Any
  • snake_case for functions and variables, PascalCase for classes
  • Dataclasses for all config objects (LocalFilesystemBackendConfig, ScopeConfig, etc.)
  • Custom error classes: BackendError, DangerousOperationError, PathEscapeError
  • Imports sorted with ruff (isort rules enabled)

Testing

Tests live in python/tests/ and use pytest with pytest-asyncio.

asyncio_mode = "auto" is configured in pyproject.toml, so async test functions are detected automatically -- no @pytest.mark.asyncio decorator needed.

Shared fixtures in conftest.py provide pre-configured backends:

@pytest.fixture
def local_backend(tmp_workspace):
    config = LocalFilesystemBackendConfig(
        root_dir=tmp_workspace,
        prevent_dangerous=True,
    )
    return LocalFilesystemBackend(config)

Use unittest.mock.AsyncMock for mocking async methods. Use the shared fixtures (local_backend, memory_backend, tmp_workspace) rather than building backends from scratch.

Running tests:

uv run pytest                            # All tests, single run
uv run pytest -k "safety"               # Filter by pattern
uv run pytest --cov=agent_backend       # With coverage report
uv run pytest -m "not integration"      # Skip integration tests

Gotchas

  • All backend methods are async -- always await them, including read, write, readdir, and exists.
  • MemoryBackend.exec() raises NotImplementedBackendError -- memory backends do not support command execution.
  • Use list_keys(prefix) on MemoryBackend, not list().
  • IsolationMode.AUTO and IsolationMode.NONE are enum members, not string literals.
  • BackendType enum values are "local-filesystem", "remote-filesystem", "memory".
  • Config objects are dataclasses, not dicts -- use keyword arguments (e.g., LocalFilesystemBackendConfig(root_dir=...)).
  • Scoped backends delegate track_closeable() to their parent, so resources are closed when the parent is destroyed.
  • destroy() closes all tracked closeables (MCP clients, transports) before tearing down the backend.
  • Coverage threshold is 80% (--cov-fail-under=80). Remote backend and transport modules are excluded from coverage.
  • ExecOptions and ReadOptions use encoding: Literal["utf8", "buffer"], not Python's standard encoding names.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_backend-0.9.7.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_backend-0.9.7-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file agent_backend-0.9.7.tar.gz.

File metadata

  • Download URL: agent_backend-0.9.7.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agent_backend-0.9.7.tar.gz
Algorithm Hash digest
SHA256 5583bfc7dff3c23d6ffb8d148196899d1e631e7bf9a4924ff864d8a8a874bcce
MD5 55ebf8e13d2c421f8c78f52a196bfc23
BLAKE2b-256 f14e4632c6a143b9b988e37cfdffacdf45bb940e7b22eefc5a2f71aff5f10426

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_backend-0.9.7.tar.gz:

Publisher: publish.yml on deepagents-ai/agent-backend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_backend-0.9.7-py3-none-any.whl.

File metadata

  • Download URL: agent_backend-0.9.7-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agent_backend-0.9.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0643b3f6768a5064b73a2181b55b3374b4d36a21fd50545b637f879e120a3ee8
MD5 54e2ecb0813e20e39dda28deb3fc2350
BLAKE2b-256 f8e0d00725627614699910a5b823e959b876ffc8393a0a8e3e5af8c2611f06c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_backend-0.9.7-py3-none-any.whl:

Publisher: publish.yml on deepagents-ai/agent-backend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page