Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Deprecate id in Python SDK
Tomas Valenta23cd829e5957
diff --git a/packages/python-sdk/e2b/sandbox/main.py b/packages/python-sdk/e2b/sandbox/main.pyindex 91e39e65d..7b61fed30 100644--- a/packages/python-sdk/e2b/sandbox/main.py+++ b/packages/python-sdk/e2b/sandbox/main.py@@ -55,7 +55,8 @@ class Sandbox(SandboxConnection):def __init__(self,- id: str = "base",+ template: str = "base",+ id: Optional[str] = None,api_key: Optional[str] = None,cwd: Optional[str] = None,env_vars: Optional[EnvVars] = None,@@ -72,11 +73,13 @@ class Sandbox(SandboxConnection):"""Create a new cloud sandbox.- :param id: ID of the sandbox template or the name of prepared template.+ :param id: [Deprecated] Use `template` param instead.+ :param template: ID of the sandbox template or the name of prepared template.Can be one of the following premade sandbox templates or a custom sandbox template ID:- `base` - A basic sandbox with a Linux environment- `Python3-DataAnalysis` - A Python3 sandbox with data analysis tools+:param api_key: The API key to use, if not provided, the `E2B_API_KEY` environment variable is used:param cwd: The current working directory to use:param on_scan_ports: A callback to handle opened ports@@ -86,7 +89,14 @@ class Sandbox(SandboxConnection)::param timeout: Timeout for sandbox to initialize in seconds, default is 60 seconds"""- logger.info(f"Creating sandbox {id if isinstance(id, str) else type(id)}")+ template = id or template or "base"++ if id:+ logger.warning("The id parameter is deprecated, use template instead.")++ logger.info(+ f"Creating sandbox {template if isinstance(template, str) else type(template)}"+ )if cwd and cwd.startswith("~"):cwd = cwd.replace("~", "/home/user")@@ -103,7 +113,7 @@ class Sandbox(SandboxConnection):on_exit=on_exit,)super().__init__(- id=id,+ template=template,api_key=api_key,cwd=cwd,env_vars=env_vars,@@ -203,10 +213,10 @@ class Sandbox(SandboxConnection)::param timeout: Specify the duration, in seconds to give the method to finish its execution before it times out (default is 60 seconds). If set to None, the method will continue to wait until it completes, regardless of time"""- logger.info(f"Opening sandbox {self._id}")+ logger.info(f"Opening sandbox {self._template}")super()._open(timeout=timeout)self._code_snippet._subscribe()- logger.info(f"Sandbox {self._id} opened")+ logger.info(f"Sandbox {self._template} opened")if self.cwd:self.filesystem.make_dir(self.cwd)diff --git a/packages/python-sdk/e2b/sandbox/run_code.py b/packages/python-sdk/e2b/sandbox/run_code.pyindex e181f3c3d..993255abb 100644--- a/packages/python-sdk/e2b/sandbox/run_code.py+++ b/packages/python-sdk/e2b/sandbox/run_code.py@@ -55,7 +55,7 @@ def run_code(f'Invalid runtime "{runtime}". Please contact us ([email protected]) if you need support for this runtime')- sandbox = Sandbox(id=env_id, api_key=api_key)+ sandbox = Sandbox(template=env_id, api_key=api_key)sandbox.filesystem.write(filepath, code)proc = sandbox.process.start(cmd=f"{binary} {filepath}")diff --git a/packages/python-sdk/e2b/sandbox/sandbox_connection.py b/packages/python-sdk/e2b/sandbox/sandbox_connection.pyindex bb17e7800..cf8d52636 100644--- a/packages/python-sdk/e2b/sandbox/sandbox_connection.py+++ b/packages/python-sdk/e2b/sandbox/sandbox_connection.py@@ -68,7 +68,7 @@ class SandboxConnection:def __init__(self,- id: str,+ template: str,api_key: Optional[str] = None,cwd: Optional[str] = None,env_vars: Optional[EnvVars] = None,@@ -87,7 +87,7 @@ class SandboxConnection:self.cwd = cwdself.env_vars = env_vars or {}- self._id = id+ self._template = templateself._api_key = api_keyself._debug_hostname = _debug_hostnameself._debug_port = _debug_port@@ -101,7 +101,7 @@ class SandboxConnection:self._rpc: Optional[SandboxRpc] = Noneself._finished = DeferredFuture(self._process_cleanup)- logger.info(f"Sandbox for template {self._id} initialized")+ logger.info(f"Sandbox for template {self._template} initialized")self._open(timeout=timeout)@@ -217,7 +217,7 @@ class SandboxConnection:api = client.InstancesApi(api_client)self._sandbox = api.instances_post(- models.NewInstance(envID=self._id),+ models.NewInstance(envID=self._template),_request_timeout=timeout,)logger.info(diff --git a/packages/python-sdk/e2b/templates/data_analysis.py b/packages/python-sdk/e2b/templates/data_analysis.pyindex 421598cde..59ea57520 100644--- a/packages/python-sdk/e2b/templates/data_analysis.py+++ b/packages/python-sdk/e2b/templates/data_analysis.py@@ -27,7 +27,7 @@ class Artifact(BaseModel):class DataAnalysis(Sandbox):- env_id = "Python3-DataAnalysis"+ template = "Python3-DataAnalysis"def __init__(self,@@ -43,7 +43,7 @@ class DataAnalysis(Sandbox):):self.on_artifact = on_artifactsuper().__init__(- id=self.env_id,+ template=self.template,api_key=api_key,cwd=cwd,env_vars=env_vars,