Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Bug: runtime.create() returns Future but is not awaited in __init__, causing AttributeError in __aenter__ #1

Description

@tmalldedede

Bug Description

When using ClaudeBox 0.3.1 with Boxlite 0.5.3, creating a ClaudeBox instance and entering the async context fails with:

AttributeError: '_asyncio.Future' object has no attribute '__aenter__'

Root Cause

In claudebox/box.py, the __init__ method calls self._runtime.create() (line 139) which returns an asyncio.Future object. However, since __init__ is synchronous, this Future is never awaited.

Later, in __aenter__ (line 156), the code tries to call await self._box.__aenter__(), but self._box is still a Future object, not a Box instance.

Problem code in box.py:

# Line 139-150 in __init__ (synchronous method)
self._box = self._runtime.create(
    BoxOptions(
        image=final_image,
        cpus=cpus,
        ...
    ),
)  # Returns Future, not Box!

# Line 155-156 in __aenter__
async def __aenter__(self) -> ClaudeBox:
    await self._box.__aenter__()  # self._box is Future, has no __aenter__

Steps to Reproduce

import asyncio
from claudebox import ClaudeBox

async def main():
    async with ClaudeBox(session_id="test") as box:
        result = await box.code("print('hello')")
        print(result.response)

asyncio.run(main())

Error Output

Traceback (most recent call last):
  File "test.py", line 8, in main
    async with ClaudeBox(session_id="test") as box:
  File ".../claudebox/box.py", line 156, in __aenter__
    await self._box.__aenter__()
AttributeError: '_asyncio.Future' object has no attribute '__aenter__'

Environment

  • ClaudeBox version: 0.3.1 (pip shows 0.3.1, but __version__ in code shows 0.2.0)
  • Boxlite version: 0.5.3
  • Python: 3.11.14
  • OS: macOS Darwin 25.1.0

Suggested Fix

In __aenter__, await the Future before calling __aenter__():

async def __aenter__(self) -> ClaudeBox:
    import asyncio
    # If self._box is a Future (from runtime.create()), await it first
    if asyncio.isfuture(self._box):
        self._box = await self._box
    await self._box.__aenter__()
    # ... rest of the method

Or alternatively, defer the runtime.create() call to __aenter__ where it can be properly awaited.

Additional Notes

  1. The __version__ in claudebox/__init__.py is hardcoded as "0.2.0" but pip shows 0.3.1 - this should be updated.

  2. The security policy names in documentation/examples may be outdated. Available policies are:

    • STANDARD_POLICY
    • READONLY_POLICY
    • UNRESTRICTED_POLICY
    • RESTRICTED_POLICY
    • RESEARCH_POLICY

    But some code examples reference STRICT_POLICY and PERMISSIVE_POLICY which don't exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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