[Python] e2b.exceptions.SandboxException: 403 client does not have permission

Discussão em 'Python' iniciado por Stack, Agosto 31, 2025.

  1. Stack

    Stack Membro Participativo

    I've been using E2B sandboxes for around 2 month. I have been distant from E2B and coding in general for a a few weeks and now that I'm back and want to test the project I was working on I'm getting this error from E2B:

    File "D:\project_path\Lib\site-packages\e2b\sandbox_async\sandbox_api.py", line 292, in _create_sandbox raise handle_api_exception(res) e2b.exceptions.SandboxException: 403: b'\n<html><head>\n<meta http-equiv="content-type" content="text/html;charset=utf-8">\n<title>403 Forbidden</title>\n</head>\n<body text=#000000 bgcolor=#ffffff>\n<h1>Error: Forbidden</h1>\n<h2>Your client does not have permission to get URL <code>/sandboxes</code> from this server.</h2>\n<h2></h2>\n</body></html>\n'

    this is (a part of) my code for a reference:

    import logging from typing import Optional, Literal

    from e2b import AsyncSandbox

    class AgentSystemSandbox:
    def __new__(cls, api_key: str, template: str, timeout: Optional[int] = None):
    if not hasattr(cls, "instance"):
    cls.instance = super(AgentSystemSandbox, cls).__new__(cls,)
    return cls.instance

    def __init__(self, api_key: str, template: str, timeout: Optional[int] = None):
    self._api_key = api_key
    self._template = template
    self._timeout = None
    self.set_timeout(timeout)
    self._sandbox = None


    async def create_sandbox(
    self,
    timeout: Optional[int] = None,
    if_exists: Literal["reuse", "create"] = "reuse",
    ) -> AsyncSandbox:
    if not timeout:
    timeout = self._timeout if self._timeout is not None else 600

    if self._api_key is None:
    raise ValueError("API key must be set before creating a sandbox")

    if self._template is None:
    raise ValueError("Template must be set before creating a sandbox")

    if self._sandbox is None:
    self._sandbox = await AsyncSandbox.create(
    template=self._template, timeout=timeout, api_key=self._api_key
    )
    elif if_exists == "create":
    self._sandbox = await AsyncSandbox.create(
    template=self._template, timeout=timeout, api_key=self._api_key
    )

    return self._sandbox


    and then in another file I have:

    import os
    import logging
    from dotenv import load_dotenv

    logger = logging.getLogger(name)

    load_dotenv()


    class EnvVarNotSet(AgentError):
    def __init__(self, msg: str):
    super().__init__("AgentSystemRuntime", msg, "ENV_VAR_NOT_SET")

    class AgentSystemRuntime:
    def __init__(self):
    self.E2B_API_KEY = os.environ.get("E2B_API_KEY", "")
    if not self.E2B_API_KEY:
    logger.error("E2B_API_KEY env var not set")
    raise EnvVarNotSet("E2B_API_KEY env var not set")
    print(f"E2b api key: {self.E2B_API_KEY}")
    self.sandbox_creator = AgentSystemSandbox(self.E2B_API_KEY, "actual-template-name", 1800)


    The template name I've written here is just a placeholder but in my own code I'm using the correct template name. I have also made sure the api key is correct. (I have even created a new one.)

    Also E2B is banned in my country so I'm using a VPN, namely V2RayN (windows x64). And I have tested this with multiple different servers (or configs) and still no luck. Note that I am checking the "Enable Tun" which makes the traffic of all apps go through the VPN including the terminal. (I've tested this by cURLing other banned URLs.)

    So what is the error caused by and how can I fix this?

    P.S: I used to get an error and I'm not exactly sure if it was this exact error, since it's been a few weeks since I worked on this. But I do know that using a VPN with Tun mode would have solved that.

    Continue reading...

Compartilhe esta Página