Metadata-Version: 2.4
Name: e2b-acp
Version: 0.1.2
Summary: Run Agent Client Protocol (ACP) agents in E2B sandboxes
Author: e2b
Author-email: e2b <hello@e2b.dev>
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Dist: e2b>=2.62.0,<3.0.0
Requires-Dist: agent-client-protocol>=0.12.1,<0.13
Requires-Python: >=3.11
Project-URL: Homepage, https://e2b.dev/docs/agents/acp?utm_source=pypi&utm_medium=referral&utm_campaign=package_homepage&utm_content=e2b-acp
Project-URL: Repository, https://github.com/e2b-dev/e2b/tree/main/packages/acp-python
Project-URL: Bug Tracker, https://github.com/e2b-dev/e2b/issues
Description-Content-Type: text/markdown

# E2B ACP

Run [Agent Client Protocol](https://agentclientprotocol.com) (ACP) agents such as goose, OpenCode or Claude Code inside an [E2B](https://e2b.dev) sandbox, and drive them from your code with the official ACP client.

Source: [packages/acp-python](https://github.com/e2b-dev/E2B/tree/main/packages/acp-python)

## Install

```
pip install e2b e2b-acp agent-client-protocol
```

Set `E2B_API_KEY` to your [E2B API key](https://e2b.dev/dashboard?tab=keys), and the provider key the agent needs.

## Usage

Create a sandbox from a template with the agent installed, then start the agent and connect your ACP client to it. The ACP Python SDK is asynchronous, so use `AsyncSandbox`.

```python
import asyncio
import os

import acp
from acp import schema
from e2b import AsyncSandbox
from e2b_acp import AsyncACPAgent


class Client:
    async def request_permission(self, session_id, tool_call, options, **kwargs):
        allow = next((o for o in options if o.kind == "allow_once"), options[0])
        return schema.RequestPermissionResponse(
            outcome=schema.AllowedOutcome(outcome="selected", option_id=allow.option_id)
        )

    async def session_update(self, session_id, update, **kwargs):
        if isinstance(update, schema.AgentMessageChunk) and update.content.type == "text":
            print(update.content.text, end="")


async def main():
    sandbox = await AsyncSandbox.create("goose", timeout=600)
    try:
        agent = AsyncACPAgent(
            sandbox,
            "goose acp --with-builtin developer",
            Client(),
            envs={
                "GOOSE_PROVIDER": "openai",
                "GOOSE_MODEL": "gpt-5.6-luna",
                "OPENAI_API_KEY": os.environ["OPENAI_API_KEY"],
            },
        )
        await agent.start()
        await agent.connection.initialize(protocol_version=acp.PROTOCOL_VERSION)
        session = await agent.connection.new_session(cwd="/home/user", mcp_servers=[])
        await agent.connection.prompt(
            session_id=session.session_id,
            prompt=[acp.text_block("Create fizzbuzz.py for 1 to 15 and run it.")],
        )
        await agent.stop()
    finally:
        await sandbox.kill()


asyncio.run(main())
```

## Where the agent's tools run

The agent talks ACP over its stdin and stdout. `AsyncACPAgent` turns off the client filesystem and terminal capabilities in `initialize` and answers agent requests for `fs/*` or `terminal/*` with an error, so the agent edits files and runs commands with its own tools inside the sandbox. It does not restrict the agent's network access or the MCP servers you pass to it.

## Lifecycle

- `AsyncACPAgent(...)` only stores the arguments; `await agent.start()` starts the agent and connects the client. `start()` can be called once.
- `agent.stop()` sends EOF to the agent and kills it if it has not exited within `timeout` (5 seconds by default) of the call. Messages the agent sends after that are not delivered. Before `start()` it does nothing, so it is safe in a `finally` block. While `start()` is still running, `stop()` and `kill()` wait for it and then stop the agent; the stop timeout counts from when the start finishes.
- `agent.wait()` returns the exit code once the agent exits. It raises `ACPException` if the agent sent a message over `max_message_bytes`.
- If the agent exits, pending requests on the connection fail with a connection error. Use `agent.wait()` for the exit code and pass `on_stderr` to receive the agent's logs.
- The agent runs as long as the sandbox does, so set the sandbox timeout for the longest task you expect.
