Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add check if template has envd V2

Jakub Novakdd8960c572c2
diff --git a/packages/js-sdk/src/api/schema.gen.ts b/packages/js-sdk/src/api/schema.gen.ts
index 3ade9e53b..d3afe6436 100644
--- a/packages/js-sdk/src/api/schema.gen.ts
+++ b/packages/js-sdk/src/api/schema.gen.ts
@@ -3,25 +3,22 @@
* Do not make direct changes to the file.
*/
-
export interface paths {
"/health": {
- /** @description Health check */
+ /** Health check */
get: {
responses: {
- /** @description Request was successful */
- 200: {
- content: never;
- };
+ /** Request was successful */
+ 200: unknown;
401: components["responses"]["401"];
};
};
};
"/sandboxes": {
- /** @description List all running sandboxes */
+ /** List all running sandboxes */
get: {
responses: {
- /** @description Successfully returned all running sandboxes */
+ /** Successfully returned all running sandboxes */
200: {
content: {
"application/json": components["schemas"]["RunningSandbox"][];
@@ -32,15 +29,10 @@ export interface paths {
500: components["responses"]["500"];
};
};
- /** @description Create a sandbox from the template */
+ /** Create a sandbox from the template */
post: {
- requestBody: {
- content: {
- "application/json": components["schemas"]["NewSandbox"];
- };
- };
responses: {
- /** @description The sandbox was created successfully */
+ /** The sandbox was created successfully */
201: {
content: {
"application/json": components["schemas"]["Sandbox"];
@@ -50,43 +42,29 @@ export interface paths {
401: components["responses"]["401"];
500: components["responses"]["500"];
};
- };
- };
- "/sandboxes/{sandboxID}": {
- /** @description Kill a sandbox */
- delete: {
- parameters: {
- path: {
- sandboxID: components["parameters"]["sandboxID"];
- };
- };
- responses: {
- /** @description The sandbox was killed successfully */
- 204: {
- content: never;
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["NewSandbox"];
};
- 401: components["responses"]["401"];
- 404: components["responses"]["404"];
- 500: components["responses"]["500"];
};
};
};
"/sandboxes/{sandboxID}/logs": {
- /** @description Get sandbox logs */
+ /** Get sandbox logs */
get: {
parameters: {
- query?: {
- /** @description Starting timestamp of the logs that should be returned in milliseconds */
- start?: number;
- /** @description Maximum number of logs that should be returned */
- limit?: number;
- };
path: {
sandboxID: components["parameters"]["sandboxID"];
};
+ query: {
+ /** Starting timestamp of the logs that should be returned in milliseconds */
+ start?: number;
+ /** Maximum number of logs that should be returned */
+ limit?: number;
+ };
};
responses: {
- /** @description Successfully returned the sandbox logs */
+ /** Successfully returned the sandbox logs */
200: {
content: {
"application/json": components["schemas"]["SandboxLogs"];
@@ -98,41 +76,39 @@ export interface paths {
};
};
};
- "/sandboxes/{sandboxID}/refreshes": {
- /** @description Refresh the sandbox extending its time to live */
- post: {
+ "/sandboxes/{sandboxID}": {
+ /** Kill a sandbox */
+ delete: {
parameters: {
path: {
sandboxID: components["parameters"]["sandboxID"];
};
};
- requestBody?: {
- content: {
- "application/json": {
- /** @description Duration for which the sandbox should be kept alive in seconds */
- duration?: number;
- };
- };
- };
responses: {
- /** @description Successfully refreshed the sandbox */
- 204: {
- content: never;
- };
+ /** The sandbox was killed successfully */
+ 204: never;
401: components["responses"]["401"];
404: components["responses"]["404"];
+ 500: components["responses"]["500"];
};
};
};
"/sandboxes/{sandboxID}/timeout": {
- /** @description Set the timeout for the sandbox. The sandbox will expire x seconds from the time of the request. Calling this method multiple times overwrites the TTL, each time using the current timestamp as the starting point to measure the timeout duration. */
+ /** Set the timeout for the sandbox. The sandbox will expire x seconds from the time of the request. Calling this method multiple times overwrites the TTL, each time using the current timestamp as the starting point to measure the timeout duration. */
post: {
parameters: {
path: {
sandboxID: components["parameters"]["sandboxID"];
};
};
- requestBody?: {
+ responses: {
+ /** Successfully set the sandbox timeout */
+ 204: never;
+ 401: components["responses"]["401"];
+ 404: components["responses"]["404"];
+ 500: components["responses"]["500"];
+ };
+ requestBody: {
content: {
"application/json": {
/**
@@ -143,22 +119,37 @@ export interface paths {
};
};
};
- responses: {
- /** @description Successfully set the sandbox timeout */
- 204: {
- content: never;
+ };
+ };
+ "/sandboxes/{sandboxID}/refreshes": {
+ /** Refresh the sandbox extending its time to live */
+ post: {
+ parameters: {
+ path: {
+ sandboxID: components["parameters"]["sandboxID"];
};
+ };
+ responses: {
+ /** Successfully refreshed the sandbox */
+ 204: never;
401: components["responses"]["401"];
404: components["responses"]["404"];
- 500: components["responses"]["500"];
+ };
+ requestBody: {
+ content: {
+ "application/json": {
+ /** @description Duration for which the sandbox should be kept alive in seconds */
+ duration?: number;
+ };
+ };
};
};
};
"/templates": {
- /** @description List all templates */
+ /** List all templates */
get: {
responses: {
- /** @description Successfully returned all templates */
+ /** Successfully returned all templates */
200: {
content: {
"application/json": components["schemas"]["Template"][];
@@ -168,15 +159,10 @@ export interface paths {
500: components["responses"]["500"];
};
};
- /** @description Create a new template */
+ /** Create a new template */
post: {
- requestBody: {
- content: {
- "application/json": components["schemas"]["TemplateBuildRequest"];
- };
- };
responses: {
- /** @description The build was accepted */
+ /** The build was accepted */
202: {
content: {
"application/json": components["schemas"]["Template"];
@@ -185,23 +171,23 @@ export interface paths {
401: components["responses"]["401"];
500: components["responses"]["500"];
};
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["TemplateBuildRequest"];
+ };
+ };
};
};
"/templates/{templateID}": {
- /** @description Rebuild an template */
+ /** Rebuild an template */
post: {
parameters: {
path: {
templateID: components["parameters"]["templateID"];
};
};
- requestBody: {
- content: {
- "application/json": components["schemas"]["TemplateBuildRequest"];
- };
- };
responses: {
- /** @description The build was accepted */
+ /** The build was accepted */
202: {
content: {
"application/json": components["schemas"]["Template"];
@@ -210,8 +196,13 @@ export interface paths {
401: components["responses"]["401"];
500: components["responses"]["500"];
};
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["TemplateBuildRequest"];
+ };
+ };
};
- /** @description Delete a template */
+ /** Delete a template */
delete: {
parameters: {
path: {
@@ -219,17 +210,15 @@ export interface paths {
};
};
responses: {
- /** @description The template was deleted successfully */
- 204: {
- content: never;
- };
+ /** The template was deleted successfully */
+ 204: never;
401: components["responses"]["401"];
500: components["responses"]["500"];
};
};
};
"/templates/{templateID}/builds/{buildID}": {
- /** @description Start the build */
+ /** Start the build */
post: {
parameters: {
path: {
@@ -238,30 +227,28 @@ export interface paths {
};
};
responses: {
- /** @description The build has started */
- 202: {
- content: never;
- };
+ /** The build has started */
+ 202: unknown;
401: components["responses"]["401"];
500: components["responses"]["500"];
};
};
};
"/templates/{templateID}/builds/{buildID}/status": {
- /** @description Get template build info */
+ /** Get template build info */
get: {
parameters: {
- query?: {
- /** @description Index of the starting build log that should be returned with the template */
- logsOffset?: number;
- };
path: {
templateID: components["parameters"]["templateID"];
buildID: components["parameters"]["buildID"];
};
+ query: {
+ /** Index of the starting build log that should be returned with the template */
+ logsOffset?: number;
+ };
};
responses: {
- /** @description Successfully returned the template */
+ /** Successfully returned the template */
200: {
content: {
"application/json": components["schemas"]["TemplateBuild"];
@@ -275,8 +262,6 @@ export interface paths {
};
}
-export type webhooks = Record<string, never>;
-
export interface components {
schemas: {
/**
@@ -284,135 +269,135 @@ export interface components {
* @description CPU cores for the sandbox
*/
CPUCount: number;
- Error: {
- /**
- * Format: int32
- * @description Error code
- */
- code: number;
- /** @description Error */
- message: string;
- };
/**
* Format: int32
* @description Memory for the sandbox in MB
*/
MemoryMB: number;
- NewSandbox: {
- metadata?: components["schemas"]["SandboxMetadata"];
- /** @description Identifier of the required template */
- templateID: string;
+ SandboxMetadata: { [key: string]: string };
+ /** @description Log entry with timestamp and line */
+ SandboxLog: {
/**
- * Format: int32
- * @description Time to live for the sandbox in seconds.
- * @default 15
+ * Format: date-time
+ * @description Timestamp of the log entry
*/
- timeout?: number;
+ timestamp: string;
+ /** @description Log line content */
+ line: string;
};
- RunningSandbox: {
+ SandboxLogs: {
+ /** @description Logs of the sandbox */
+ logs: components["schemas"]["SandboxLog"][];
+ };
+ Sandbox: {
+ /** @description Identifier of the template from which is the sandbox created */
+ templateID: string;
+ /** @description Identifier of the sandbox */
+ sandboxID: string;
/** @description Alias of the template */
alias?: string;
/** @description Identifier of the client */
clientID: string;
- cpuCount: components["schemas"]["CPUCount"];
- memoryMB: components["schemas"]["MemoryMB"];
- metadata?: components["schemas"]["SandboxMetadata"];
+ /** @description Whether the template contains envd v2 */
+ envdV2: boolean;
+ };
+ RunningSandbox: {
+ /** @description Identifier of the template from which is the sandbox created */
+ templateID: string;
+ /** @description Alias of the template */
+ alias?: string;
/** @description Identifier of the sandbox */
sandboxID: string;
+ /** @description Identifier of the client */
+ clientID: string;
/**
* Format: date-time
* @description Time when the sandbox was started
*/
startedAt: string;
- /** @description Identifier of the template from which is the sandbox created */
- templateID: string;
+ cpuCount: components["schemas"]["CPUCount"];
+ memoryMB: components["schemas"]["MemoryMB"];
+ metadata?: components["schemas"]["SandboxMetadata"];
};
- Sandbox: {
- /** @description Alias of the template */
- alias?: string;
- /** @description Identifier of the client */
- clientID: string;
- /** @description Identifier of the sandbox */
- sandboxID: string;
- /** @description Identifier of the template from which is the sandbox created */
+ NewSandbox: {
+ /** @description Identifier of the required template */
templateID: string;
- };
- /** @description Log entry with timestamp and line */
- SandboxLog: {
- /** @description Log line content */
- line: string;
/**
- * Format: date-time
- * @description Timestamp of the log entry
+ * Format: int32
+ * @description Time to live for the sandbox in seconds.
+ * @default 15
*/
- timestamp: string;
- };
- SandboxLogs: {
- /** @description Logs of the sandbox */
- logs: components["schemas"]["SandboxLog"][];
- };
- SandboxMetadata: {
- [key: string]: string;
+ timeout?: number;
+ metadata?: components["schemas"]["SandboxMetadata"];
};
Template: {
- /** @description Aliases of the template */
- aliases?: string[];
+ /** @description Identifier of the template */
+ templateID: string;
/** @description Identifier of the last successful build for given template */
buildID: string;
cpuCount: components["schemas"]["CPUCount"];
memoryMB: components["schemas"]["MemoryMB"];
/** @description Whether the template is public or only accessible by the team */
public: boolean;
- /** @description Identifier of the template */
- templateID: string;
+ /** @description Aliases of the template */
+ aliases?: string[];
+ };
+ TemplateBuildRequest: {
+ /** @description Alias of the template */
+ alias?: string;
+ /** @description Dockerfile for the template */
+ dockerfile: string;
+ /** @description Start command to execute in the template after the build */
+ startCmd?: string;
+ cpuCount?: components["schemas"]["CPUCount"];
+ memoryMB?: components["schemas"]["MemoryMB"];
};
TemplateBuild: {
- /** @description Identifier of the build */
- buildID: string;
/**
* @description Build logs
* @default []
*/
logs: string[];
+ /** @description Identifier of the template */
+ templateID: string;
+ /** @description Identifier of the build */
+ buildID: string;
/**
* @description Status of the template
* @enum {string}
*/
status: "building" | "ready" | "error";
- /** @description Identifier of the template */
- templateID: string;
};
- TemplateBuildRequest: {
- /** @description Alias of the template */
- alias?: string;
- cpuCount?: components["schemas"]["CPUCount"];
- /** @description Dockerfile for the template */
- dockerfile: string;
- memoryMB?: components["schemas"]["MemoryMB"];
- /** @description Start command to execute in the template after the build */
- startCmd?: string;
+ Error: {
+ /**
+ * Format: int32
+ * @description Error code
+ */
+ code: number;
+ /** @description Error */
+ message: string;
};
};
responses: {
- /** @description Bad request */
+ /** Bad request */
400: {
content: {
"application/json": components["schemas"]["Error"];
};
};
- /** @description Authentication error */
+ /** Authentication error */
401: {
content: {
"application/json": components["schemas"]["Error"];
};
};
- /** @description Not found */
+ /** Not found */
404: {
content: {
"application/json": components["schemas"]["Error"];
};
};
- /** @description Server error */
+ /** Server error */
500: {
content: {
"application/json": components["schemas"]["Error"];
@@ -420,17 +405,12 @@ export interface components {
};
};
parameters: {
+ templateID: string;
buildID: string;
sandboxID: string;
- templateID: string;
};
- requestBodies: never;
- headers: never;
- pathItems: never;
}
-export type $defs = Record<string, never>;
-
-export type external = Record<string, never>;
+export interface operations {}
-export type operations = Record<string, never>;
+export interface external {}
diff --git a/packages/js-sdk/src/sandbox/sandboxApi.ts b/packages/js-sdk/src/sandbox/sandboxApi.ts
index 128a7b1d5..ac6268b02 100644
--- a/packages/js-sdk/src/sandbox/sandboxApi.ts
+++ b/packages/js-sdk/src/sandbox/sandboxApi.ts
@@ -123,6 +123,12 @@ export class SandboxApi {
throw err
}
+ if (!res.data!.envdV2) {
+ throw new Error(
+ 'You need to update the template to use the new SDK. ' +
+ 'You can do this by running `e2b template build` in the directory with the template.'
+ )
+ }
return this.getSandboxID(res.data!)
}
diff --git a/packages/python-sdk/e2b/api/v1/client/models/sandbox.py b/packages/python-sdk/e2b/api/v1/client/models/sandbox.py
index af50a02c1..fc8746f43 100644
--- a/packages/python-sdk/e2b/api/v1/client/models/sandbox.py
+++ b/packages/python-sdk/e2b/api/v1/client/models/sandbox.py
@@ -19,7 +19,7 @@ import json
from typing import Any, Dict, Optional
-from pydantic import BaseModel, Field, StrictStr
+from pydantic import BaseModel, Field, StrictBool, StrictStr
class Sandbox(BaseModel):
@@ -39,8 +39,11 @@ class Sandbox(BaseModel):
client_id: StrictStr = Field(
..., alias="clientID", description="Identifier of the client"
)
+ envd_v2: StrictBool = Field(
+ ..., alias="envdV2", description="Whether the template contains envd v2"
+ )
additional_properties: Dict[str, Any] = {}
- __properties = ["templateID", "sandboxID", "alias", "clientID"]
+ __properties = ["templateID", "sandboxID", "alias", "clientID", "envdV2"]
class Config:
"""Pydantic configuration"""
@@ -88,6 +91,7 @@ class Sandbox(BaseModel):
"sandbox_id": obj.get("sandboxID"),
"alias": obj.get("alias"),
"client_id": obj.get("clientID"),
+ "envd_v2": obj.get("envdV2"),
}
)
# store additional fields in additional_properties
diff --git a/packages/python-sdk/e2b/api/v2/client/models/sandbox.py b/packages/python-sdk/e2b/api/v2/client/models/sandbox.py
index 4f9f82e3d..a33d916a0 100644
--- a/packages/python-sdk/e2b/api/v2/client/models/sandbox.py
+++ b/packages/python-sdk/e2b/api/v2/client/models/sandbox.py
@@ -19,7 +19,7 @@ import json
from typing import Any, ClassVar, Dict, List, Optional
-from pydantic import BaseModel, StrictStr
+from pydantic import BaseModel, StrictBool, StrictStr
from pydantic import Field
try:
@@ -46,8 +46,17 @@ class Sandbox(BaseModel):
client_id: StrictStr = Field(
description="Identifier of the client", alias="clientID"
)
+ envd_v2: StrictBool = Field(
+ description="Whether the template contains envd v2", alias="envdV2"
+ )
additional_properties: Dict[str, Any] = {}
- __properties: ClassVar[List[str]] = ["templateID", "sandboxID", "alias", "clientID"]
+ __properties: ClassVar[List[str]] = [
+ "templateID",
+ "sandboxID",
+ "alias",
+ "clientID",
+ "envdV2",
+ ]
model_config = {"populate_by_name": True, "validate_assignment": True}
@@ -105,6 +114,7 @@ class Sandbox(BaseModel):
"sandboxID": obj.get("sandboxID"),
"alias": obj.get("alias"),
"clientID": obj.get("clientID"),
+ "envdV2": obj.get("envdV2"),
}
)
# store additional fields in additional_properties
diff --git a/packages/python-sdk/e2b/sandbox/sandbox_api.py b/packages/python-sdk/e2b/sandbox/sandbox_api.py
index e40703913..67f2e6f3d 100644
--- a/packages/python-sdk/e2b/sandbox/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox/sandbox_api.py
@@ -7,6 +7,12 @@ from e2b.connection_config import ConnectionConfig
from e2b.api import handle_api_exception
+class E2BUpdateTemplateException(Exception):
+ """
+ Exception raised when the template uses old envd version. It isn't compatible with the new SDK.
+ """
+
+
@dataclass
class SandboxInfo:
"""Information about a sandbox."""
@@ -139,6 +145,11 @@ class SandboxApi:
),
_request_timeout=config.request_timeout,
)
+ if not res.envd_v2:
+ raise E2BUpdateTemplateException(
+ "You need to update the template to use the new SDK. "
+ "You can do this by running `e2b template build` in the directory with the template."
+ )
return SandboxApi._get_sandbox_id(res.sandbox_id, res.client_id)
except exceptions.ApiException as e:
raise handle_api_exception(e)
diff --git a/spec/openapi.yml b/spec/openapi.yml
index 0db581de9..10b4ad261 100644
--- a/spec/openapi.yml
+++ b/spec/openapi.yml
@@ -113,6 +113,7 @@ components:
- templateID
- sandboxID
- clientID
+ - envdV2
properties:
templateID:
type: string
@@ -126,6 +127,9 @@ components:
clientID:
type: string
description: Identifier of the client
+ envdV2:
+ type: boolean
+ description: Whether the template contains envd v2
RunningSandbox:
required: