Code: Select all
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\n
\n
403 Forbidden\n
\n
\n
`**`Error: Forbidden\n
Your client does not have permission to get URL /sandboxes
\n
\n'
< /code>
Dies ist (ein Teil von) mein Code als Referenz: < /p>
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
< /code>
Und dann habe ich in einer anderen Datei: < /p>
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)
< /code>
Der Vorlagenname, den ich hier geschrieben habe, ist nur ein Platzhalter, aber in meinem eigenen Code verwende ich den richtigen Vorlagennamen. Ich habe auch dafür gesorgt, dass der API -Schlüssel korrekt ist. (Ich habe sogar eine neue erstellt.) < /P>
Auch E2B ist in meinem Land verboten, also verwende ich ein VPN, nämlich V2RAYN (Windows x64). Beachten Sie, dass ich den "Tunable Enable" überprüfe, wodurch der Verkehr aller Apps das VPN einschließlich des Terminals durchläuft. (Ich habe dies getestet, indem ich andere verbotene URLs zusammenrollte.) < /P>
Wie ist der Fehler, und wie kann ich dies beheben? Aber ich weiß, dass die Verwendung eines VPN mit dem TUN -Modus das gelöst hätte.