You are reading a legacy (pre v1.0) document.
e2b) and Code Interpreter SDKs (@e2b/code-interpreter/e2b-code-interpreter) to the beta versions.
The latest beta versions you should install can be found in NPM/PyPi release history:
- JavaScript & TypeScript
- Latest release with rc tag for
e2b - Latest release with rc tag for
@e2b/code-interpreter
- Latest release with rc tag for
- Python
- Latest release with PRE-RELEASE for
e2b - Latest release with PRE-RELEASE for
e2b-code-interpreter
- Latest release with PRE-RELEASE for
Table of contents
- Core Sandbox SDK changes
- Creating sandbox
- Modifying sandbox timeout
- Reconnecting
- Writing files to sandbox
- Reading files from sandbox
- Uploading data to sandbox
- Downloading files from sandbox
- Running processes
- Watching for files’ changes
- Accessing sandbox ID
- Getting sandbox upload URL
- Configuring sandbox
cwd - Timeouts
- Listing sandboxes
- Getting sandbox url
- Code Interpreter SDK changes
- Executing code
- Custom template
- Python Async
Core Sandbox SDK changes
These changes affect both the e2b Core SDKs and Code Interpreter SDKs (@e2b/code-interpreter/e2b-code-interpreter) because the Code Interpreter uses the Core SDK.
If you are using a custom template you need to rebuild it by calling
e2b template build in the directory with the template.Creating sandbox
When creating a sandbox you now specify the sandbox timeout — how long the sandbox will exist. If you don’t specify the timeout the sandbox will be closed after 5 minutes. You also no longer call the.close() method when you are done with the sandbox. Sandbox will be automatically closed and killed after the timeout.
You can use .kill() to kill the sandbox immediately if you are sure you won’t need it anymore.
Modifying sandbox timeout
If you need to change how long the sandbox should stay alive after it was created, you can use.setTimeout()/.set_timeout() method.
It will modify the timeout of the sandbox.
Reconnecting
When connection to an existing sandbox use.connect()/.connect() method instead of .reconnect()/.reconnect().
Instead of using .keepAlive()/.keep_alive() method to prevent the sandbox from closing until you reconnect use .setTimeout()/.set_timeout() method.
Because the timeout is set when the sandbox is created, you may not need to set the timeout when reconnecting at all now.
Writing files to sandbox
Use.files.write() method to write files to the sandbox.
The method accepts path in the sandbox as the first argument and the data as the second argument.
Reading files from sandbox
Use.files.read() method to read files from the sandbox.
The method accepts path in the sandbox as the first argument and optional format as the second argument.
Uploading data to sandbox
Use.files.write() method to upload files to the sandbox.
The method accepts path in the sandbox as the first argument and the data as the second argument.
Downloading files from sandbox
Use.files.read() method to download files from the sandbox.
The method accepts path in the sandbox as the first argument and optional format as the second argument.
Running processes
You execute processes by calling.commands.run() method. By default, the method waits for the command to finish.
You can specify the timeout for the command execution by passing timeoutMs/timeout option. The default timeout is 60 seconds.
If the command fails with a non-zero exit it will raise CommandExitError in Javascript, or CommandExitException in Python, and you can catch and inspect the error for more info.
background: true/background=True option.
You can then use .wait() method to wait for the command to finish.
Watching for files’ changes
Accessing sandbox ID
Theid property on the sandbox/code interpreter instance is now named sandboxId/sandbox_id.
Getting sandbox upload URL
The.fileURL/.file_url() is now .uploadURL/.upload_url() method that takes an optional argument that specifies the path in the sandbox where the file will be uploaded.
If the path is not specified the file will be uploaded to the home dir — /home/user.
Configuring sandbox cwd
Previously you could set the sandbox working directory by passing cwd option when creating the sandbox.
Right now this is not supported because it leads to subtle bugs especially when reconnecting to an existing sandbox.
If you need this feature please reach out to us on Discord or GitHub so we can prioritize it.
Timeouts
There are now two types of timeouts that you can pass as parameters:request_timeout/requestTimeoutMssets how long the operation should wait for connection/processing. This is useful for ensuring that none of the sandbox operations hang indefinitely.timeout/timeoutMswhich is used for setting the maximum length of long-running operations like executing code, running processes, or the sandbox itself.
Listing sandboxes
Some properties returned from theSandbox.list method have been renamed.
Getting sandbox url
The method for getting the sandbox host has changed fromsandbox.getHostname/sandbox.get_hostname to sandbox.getHost/sandbox.get_host.
It now requires specifying the port.
Code Interpreter SDK changes
All the previously mentioned changes to the Core SDK also apply to the Code Interpreter SDK.
Apart from them, the changes to the Code Interpreter SDK are very minimal:
Executing code
When executing code via JS/TS Code Interpreter SDK you now pass thetimeoutMs option to the execCell method instead of timeout.
The default timeout for the code execution is now 300 seconds.
Custom template
If you are using a custom template for the Code Interpreter you need to rebuild it. You can rebuild the template by either callinge2b.Dockerfile
e2b.toml from beta template
to the directory with your template and then run e2b template build -c "/root/.jupyter/start-up.sh".
Check of the Code Interpreter custom template page for more info.
Python Async
Python Core SDK and Code Interpter SDK now support async.
If you need to use async import AsyncSandbox/AsyncCodeInterpreter instead of Sandbox/CodeInterpreter.