Skip to content

An open-source, faster Devin alternative

TypeScript

Add CPU/memory controls to SDKs with server-side validation

motatoes2ad3202d5c02
diff --git a/internal/api/sandbox.go b/internal/api/sandbox.go
index 649014a0..365ffb55 100644
--- a/internal/api/sandbox.go
+++ b/internal/api/sandbox.go
@@ -22,6 +22,24 @@ func (s *Server) createSandbox(c echo.Context) error {
})
}
+ // Validate and clamp CPU/memory limits
+ if cfg.CpuCount < 0 {
+ cfg.CpuCount = 0
+ }
+ if cfg.CpuCount > 4 {
+ return c.JSON(http.StatusBadRequest, map[string]string{
+ "error": "cpuCount must not exceed 4",
+ })
+ }
+ if cfg.MemoryMB > 2048 {
+ return c.JSON(http.StatusBadRequest, map[string]string{
+ "error": "memoryMB must not exceed 2048",
+ })
+ }
+ if cfg.MemoryMB < 0 {
+ cfg.MemoryMB = 0
+ }
+
ctx := c.Request().Context()
// Check org quota if PG is available
diff --git a/internal/sandbox/manager.go b/internal/sandbox/manager.go
index c192e9c5..18e191b0 100644
--- a/internal/sandbox/manager.go
+++ b/internal/sandbox/manager.go
@@ -22,8 +22,10 @@ const (
defaultTimeout = 300 // 5 minutes
defaultImage = "docker.io/library/ubuntu:22.04"
- defaultMemoryMB = 512
+ defaultMemoryMB = 1024
defaultCPU = 1
+ maxMemoryMB = 2048
+ maxCPU = 4
)
// Manager handles sandbox lifecycle operations (pure container executor).
diff --git a/sdks/python/opensandbox/__init__.py b/sdks/python/opensandbox/__init__.py
index 69135aef..919b19dd 100644
--- a/sdks/python/opensandbox/__init__.py
+++ b/sdks/python/opensandbox/__init__.py
@@ -16,4 +16,4 @@ __all__ = [
"Template",
]
-__version__ = "0.1.0"
+__version__ = "0.3.0"
diff --git a/sdks/python/pyproject.toml b/sdks/python/pyproject.toml
index 7687df16..351e7346 100644
--- a/sdks/python/pyproject.toml
+++ b/sdks/python/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "opensandbox-sdk"
-version = "0.2.0"
+version = "0.3.0"
description = "Python SDK for OpenSandbox - E2B-compatible sandbox platform"
readme = "README.md"
requires-python = ">=3.10"
diff --git a/sdks/typescript/package.json b/sdks/typescript/package.json
index a812e0fc..38185bab 100644
--- a/sdks/typescript/package.json
+++ b/sdks/typescript/package.json
@@ -1,6 +1,6 @@
{
"name": "opensandbox",
- "version": "0.3.0",
+ "version": "0.4.0",
"description": "TypeScript SDK for OpenSandbox - E2B-compatible sandbox platform",
"type": "module",
"main": "dist/index.js",
diff --git a/sdks/typescript/src/sandbox.ts b/sdks/typescript/src/sandbox.ts
index e17d850b..984bc247 100644
--- a/sdks/typescript/src/sandbox.ts
+++ b/sdks/typescript/src/sandbox.ts
@@ -14,6 +14,8 @@ export interface SandboxOpts {
apiUrl?: string;
envs?: Record<string, string>;
metadata?: Record<string, string>;
+ cpuCount?: number;
+ memoryMB?: number;
}
interface SandboxData {
@@ -71,6 +73,8 @@ export class Sandbox {
};
if (opts.envs) body.envs = opts.envs;
if (opts.metadata) body.metadata = opts.metadata;
+ if (opts.cpuCount != null) body.cpuCount = opts.cpuCount;
+ if (opts.memoryMB != null) body.memoryMB = opts.memoryMB;
const resp = await fetch(`${apiUrl}/sandboxes`, {
method: "POST",