Skip to main content

E2B SDK that give agents cloud environments

Reason this release was yanked:

This version is deprecated. Please migrate to v1. Migration guide: https://e2b.dev/docs/quickstart/migrating-from-v0

Project description

E2B Python SDK

The E2B Python SDK provides an interface for managing cloud environments for AI agents.

This SDK gives your agent a full cloud development environment that's sandboxed. That means:

  • Access to Linux OS
  • Using filesystem (create, list, and delete files and dirs)
  • Run processes
  • Sandboxed - you can run any code
  • Access to the internet

These cloud environments are meant to be used for agents. Like a sandboxed playgrounds, where the agent can do whatever it wants.

Installation

pip install e2b

Usage

Initialize new cloud environment session

from e2b import Session
# You can use some of the predefined environments by using specific id:
# 'Nodejs', 'Bash', 'Python3', 'Java', 'Go', 'Rust', 'PHP', 'Perl', 'DotNET'
session = Session(id="Nodejs", on_scan_ports=lambda ports: print("Open ports", ports))

# Start a session and create a connection to it
await session.open()

...

# Close the session after you are done
await session.close()

Use filesystem inside cloud environment

# List
dir_b_content = await session.filesystem.list("/dirA/dirB")

# Write
# This will create a new file "file.txt" inside the dir "dirB" with the content "Hello world".
await session.filesystem.write("/dirA/dirB/file.txt", "Hello World")

# Read
file_content = await session.filesystem.read("/dirA/dirB/file.txt")

# Remove
# Remove a file.
await session.filesystem.remove("/dirA/dirB/file.txt")
# Remove a directory and all of its content.
await session.filesystem.remove("/dirA")

# Make dir
# Creates a new directory "dirC" and also "dirA" and "dirB" if those directories don"t already exist.
await session.filesystem.make_dir("/dirA/dirB/dirC")

# Watch dir for changes
watcher = session.filesystem.watch_dir("/dirA/dirB")
watcher.add_event_listener(lambda e: print("Event", e))
await watcher.start()

Start process inside cloud environment

proc = await session.process.start(
  cmd="echo Hello World",
  on_stdout=on_stdout,
  on_stderr=on_stderr,
  on_exit=lambda: print("Exit"),
  rootdir="/code",
)

await proc.send_stdin("\n")

print(proc.process_id)

await proc.kill()

# Wait for process to finish
await proc.finished

Create interactive terminal inside cloud environment

term = await session.terminal.start(
    on_data=lambda data: print("Data", data),
    on_exit=lambda: print("Exit"),
    cols=80,
    rows=24,
    rootdir="/code",
    # If you specify a command, the terminal will be closed after the command finishes.
    # cmd="echo Hello World",
)

await term.send_data("echo 1\n")

await term.resize(80, 30)

print(term.terminal_id)

await term.kill()

Get public hostname for an exposed port inside cloud environment

# Get hostname for port 3000. The hostname is without the protocol (http://).
hostname = await session.get_hostname(3000)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

e2b-0.1.4.tar.gz (40.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

e2b-0.1.4-py3-none-any.whl (71.3 kB view details)

Uploaded Python 3

File details

Details for the file e2b-0.1.4.tar.gz.

File metadata

  • Download URL: e2b-0.1.4.tar.gz
  • Upload date:
  • Size: 40.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0

File hashes

Hashes for e2b-0.1.4.tar.gz
Algorithm Hash digest
SHA256 beb1e787b58312038f022185a4ae6df81bd02d19d63dd07e8898a5e90f1f647d
MD5 b2f27539b8a64a340dc99cf85c84c170
BLAKE2b-256 d64d3b62e1037a5e563b24e7a5242930c4e5f008c241facb1b571c4543dd4f4e

See more details on using hashes here.

File details

Details for the file e2b-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: e2b-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 71.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0

File hashes

Hashes for e2b-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d95d708122f95eba2aae839b78b8acd10df41320e2822083da73682d52249463
MD5 689204e5624b239db2f9c52872d6d046
BLAKE2b-256 332e5c9baa4cd99b88b3d02146043d3f1f53b3dea2601aae28e891e3b8700fd5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page