e2b@2.1.0
### Merge Templates SDK into E2B SDK.
This PR merges code from Templates SDK to E2B SDK.
**Changelog**
- Added new error classes: BuildError, FileUploadError.
- Added template API endpoints to API Client generation (Python).
- Updated API Clients error handling to throw BuildError in addition to
SandboxError.
- Exported Template and TemplateAsync classes.
- Moved `getRuntime` utility method from api to utils.
- Browser is supported except file operations (COPY). Incompatible
modules are not bundled, using dynamic imports (tar, glob) in supported
environments (Node, Deno, Bun) instead.
- Basic tests were added, subject to expansion in a follow-up PR.
- Breaking: Before, 401 error was raising `SandboxError`, which was
incorrect, now it will raise `AuthenticationError`. I have also changed
the `AuthenticationError` to extend Error class, not `SandboxError`
anymore as it's now thrown by both Sandbox and Template.
**Usage**
JavaScript
```js
import { Template } from 'e2b';
const template = Template()
.fromImage('ubuntu:22.04')
.copy('folder/*.txt', 'folder', { forceUpload: true })
.setEnvs({
ENV_1: 'value1',
ENV_2: 'value2',
})
.runCmd('cat folder/test.txt')
.setWorkdir('/app')
.setStartCmd('echo "Hello, world!"', Template.waitForTimeout('10s'))
await Template.build(template, {
alias: 'test-template',
cpuCount: 1,
memoryMB: 1024,
onBuildLogs: (logEntry) => console.log(logEntry.toString()),
})
```
Python
```py
from e2b import Template
template = (
Template()
.from_image("ubuntu:22.04")
.copy("folder/*.txt", "folder", force_upload=True)
.set_envs(
{
"ENV_1": "value1",
"ENV_2": "value2",
}
)
.run_cmd("cat folder/test.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", Template.wait_for_timeout("10s"))
)
Template.build(
template,
alias="test-template",
cpu_count=1,
memory_mb=1024,
on_build_logs=lambda log_entry: print(log_entry),
)
```
Python Async
```py
from e2b import AsyncTemplate
template = (
AsyncTemplate()
.from_image("ubuntu:22.04")
.copy("folder/*.txt", "folder", force_upload=True)
.set_envs(
{
"ENV_1": "value1",
"ENV_2": "value2",
}
)
.run_cmd("cat folder/test.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", Template.wait_for_timeout("10s"))
)
await AsyncTemplate.build(
template,
alias="test-template",
cpu_count=1,
memory_mb=1024,
on_build_logs=lambda log_entry: print(log_entry),
)
```
---
Merge progress
- [x] JavaScript SDK
- [x] Python SDK
- [x] Tests
- [x] Split files for review
What is E2B?
E2B is an open-source infrastructure that allows you to run AI-generated code in secure isolated sandboxes in the cloud. To start and control sandboxes, use our JavaScript SDK or Python SDK.
Note
This repository contains the core E2B SDK that's used in our main E2B Code Interpreter SDK.
Run your first Sandbox
1. Install SDK
JavaScript / TypeScript
npm i @e2b/code-interpreter
Python
pip install e2b-code-interpreter
2. Get your E2B API key
E2B_API_KEY=e2b_***
3. Execute code with code interpreter inside Sandbox
JavaScript / TypeScript
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create()
await sandbox.runCode('x = 1')
const execution = await sandbox.runCode('x+=1; x')
console.log(execution.text) // outputs 2
Python
from e2b_code_interpreter import Sandbox
with Sandbox.create() as sandbox:
sandbox.run_code("x = 1")
execution = sandbox.run_code("x+=1; x")
print(execution.text) # outputs 2
4. Check docs
Visit E2B documentation.
5. E2B cookbook
Visit our Cookbook to get inspired by examples with different LLMs and AI frameworks.
Self-hosting
Read the self-hosting guide to learn how to set up the E2B infrastructure on your own. The infrastructure is deployed using Terraform.
Supported cloud providers:
- 🟢 GCP
- 🚧 AWS
- Azure
- General linux machine
Description
E2B 是开源的安全运行时环境,为企业级 AI Agent 提供真实工具支持。|GitHub 镜像 ⭐ 13.6k · 🍴 1k
https://github.com/e2b-dev/e2b
Readme
Apache-2.0
129 MiB
Languages
Python
57.1%
TypeScript
42.2%
Dockerfile
0.3%
JavaScript
0.1%
Makefile
0.1%
Other
0.1%

