Repository: harbor-framework/harbor
Issue: E2B template "Alias `xxx` is already taken"
Root cause: External Dependency Breakage

# Summary
The E2B environment requires template names to be globally unique rather than scoped per user. If User 1 and User 2 both attempt to create a template with the same name (e.g., `xxx`), the build fails with a conflict error.

**Error:**

```
e2b.exceptions.BuildException: 400: Alias xxx is already taken

```
## Root Cause

In `src/harbor/environments/e2b.py`, the `_template_name` is currently defined as:

```python
self._template_name = f"{environment_name}__{user_signature}__{dirhash(self.environment_dir, 'sha256')[:8]}".replace(
    ".", "-"
)

```

The logic fails to prevent collisions when the resulting string is already registered globally in the E2B ecosystem. You can verify this error by running
```python
harbor run -p ./harbor/examples/tasks/hello-world -a oracle -e e2b -n 1
```
## Impact
- All E2B users might face this issue unless they modify the template name themselves

## Proposed Solution 
Add a personal signature to the template name to the template.

```python
    def __init__(
        self,
        environment_dir: Path,
        environment_name: str,
        session_id: str,
        trial_paths: TrialPaths,
        task_env_config: EnvironmentConfig,
        user_signature: str = "",
        *args,
        **kwargs,
    ):
        super().__init__(
            environment_dir=environment_dir,
            environment_name=environment_name,
            session_id=session_id,
            trial_paths=trial_paths,
            task_env_config=task_env_config,
            **kwargs,
        )
        assert isinstance(user_signature, str) and user_signature != "", "Please provide a valid, non-empty user_signature string"
        self._user_signature = user_signature
        ...
        self._template_name = f"{environment_name}__{self._user_signature}__{dirhash(self.environment_dir, 'sha256')[:8]}".replace(
            ".", "-"
        )
```

You mean if I build an e2b template on my account and you build one on yours with the same name, we would get a name clash? That doesn't seem right to me, but i can check with the e2b folks.

Yeah, i have this script below to reproduce this error.

```python
import asyncio
from e2b import AsyncTemplate, Template

async def test():
    alias = "build-pmars__97980b3a"  # Alias from Terminal-Bench run

    template = Template().from_dockerfile(
        dockerfile_content_or_path="FROM ubuntu:24.04\nWORKDIR /app"
    )

    try:
        await AsyncTemplate.build(
            template=template,
            alias=alias,
            cpu_count=1,
            memory_mb=512,
        )
        print(f"✅ Template created: {alias}")
    except Exception as e:
        print(f"❌ Error: {e}")

asyncio.run(test())
```
I got this error from E2B 
```bash
Response 400
❌ Error: 400: Alias `build-pmars__97980b3a` is already taken
```

The template alias `build-pmars__97980b3a` is from the terminal-bench logic for `build-pmars` task

I don't know if it is because someone ran harbor on E2B before and made the template public so that others can't use the same alias even if it is private

@alexgshaw yes it's an actual issue with e2b, sandbox names should be unique across all e2b users

https://github.com/e2b-dev/E2B/issues/1006

Solution can be to add random uuid or session/trial_id to sandbox name


Thanks for confirming this. I can create a PR to fix it with uuid.

Hey,
I work on E2B, we have just added a method to check the alias availability, here are the docs:
https://e2b.dev/docs/template/aliases

E2B is releasing a change soon that will remove the global uniqueness constraint on template aliases which will improve this whole use case

E2B released this change, use any template name you like