Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
(docs) Add docs for reading and writing bytes
Vasek Mlejnsky2345e4933a33
diff --git a/apps/docs/src/app/playgrounds/filesystem/page.mdx b/apps/docs/src/app/playgrounds/filesystem/page.mdxindex 2cd1ffafa..351a3707c 100644--- a/apps/docs/src/app/playgrounds/filesystem/page.mdx+++ b/apps/docs/src/app/playgrounds/filesystem/page.mdx@@ -8,32 +8,65 @@ export const sections = [{ title: 'Create directory', id: 'create-directory' },{ title: 'Write to file', id: 'write-to-file' },{ title: 'Read from file', id: 'read-file' },- // { title: 'Write bytes', id: 'write-bytes' },- // { title: 'Read bytes', id: 'read-bytes' },+ { title: 'Write bytes', id: 'write-bytes' },+ { title: 'Read bytes', id: 'read-bytes' },{ title: 'Watch directory for changes', id: 'watch-directory-for-changes' },]## List directory-<CodeGroupAutoload path="basics/fs_ls" isRunnable={true} />++<CodeGroupAutoload+ path="basics/fs_ls"+ isRunnable={true}+/>## Create directoryA creation of a directory will fail if any directory on the path doesn't exist yet.For example, if you want to create a directory `/home/user/new_dir` and `/home/user` doesn't exist yet, you will get an error.-<CodeGroupAutoload path="basics/fs_mkdir" isRunnable={false} />+<CodeGroupAutoload+ path="basics/fs_mkdir"+ isRunnable={false}+/>## Write to file+When writing to a file that doesn't exist, it will get created.When writing to a file that already exists, it will get overwritten.When writing to a file that's in a directory that doesn't exist, you'll get an error.-<CodeGroupAutoload path="basics/fs_write" isRunnable={false} />+<CodeGroupAutoload+ path="basics/fs_write"+ isRunnable={true}+/>## Read from file-<CodeGroupAutoload path="basics/fs_read" isRunnable={true} />++<CodeGroupAutoload+ path="basics/fs_read"+ isRunnable={true}+/>++## Write bytes++<CodeGroupAutoload+ path="basics/fs_write_bytes"+ isRunnable={true}+/>++## Read bytes++<CodeGroupAutoload+ path="basics/fs_read_bytes"+ isRunnable={true}+/>## Watch directory for changes-<CodeGroupAutoload path="basics/fs_watch" isRunnable={false} />++<CodeGroupAutoload+ path="basics/fs_watch"+ isRunnable={false}+/>diff --git a/apps/docs/src/code/python/_run_all.py b/apps/docs/src/code/python/_run_all.pyindex d9c1dcef5..ffecee753 100644--- a/apps/docs/src/code/python/_run_all.py+++ b/apps/docs/src/code/python/_run_all.py@@ -7,6 +7,8 @@ from basics.fs_ls import main as fs_ls_mainfrom basics.fs_mkdir import main as fs_mkdir_mainfrom basics.fs_read import main as fs_read_mainfrom basics.fs_write import main as fs_write_main+from basics.fs_read_bytes import main as fs_read_bytes_main+from basics.fs_write_bytes import main as fs_write_bytes_mainfrom basics.fs_watch import main as fs_watch_mainfrom basics.process_start import main as process_start_mainfrom basics.process_stop import main as process_stop_maindiff --git a/apps/docs/src/code/python/basics/fs_read_bytes.py b/apps/docs/src/code/python/basics/fs_read_bytes.pyindex 6845f1c6b..de13174cd 100644--- a/apps/docs/src/code/python/basics/fs_read_bytes.py+++ b/apps/docs/src/code/python/basics/fs_read_bytes.py@@ -7,6 +7,17 @@ E2B_API_KEY = getenv("E2B_API_KEY")async def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)+ # File bytes will read file's content as bytes+ # `file_bytes` as a bytearray+ file_bytes = await session.filesystem.read_bytes('/etc/hosts') # $HighlightLine++ # The output will look similar to this:+ # b'127.0.0.1\tlocalhost\n::1\tlocalhost ip6-localhost ip6-loopback\nfe00::0\tip6-localnet\nff00::0\tip6-mcastprefix\nff02::1\tip6-allnodes\nff02::2\tip6-allrouters\n172.17.0.17\t77c7a543226b\n'+ print(file_bytes)++ # We can save those bytes to a file locally like this:+ with open('./hosts.txt', 'wb') as f:+ f.write(file_bytes)await session.close()diff --git a/apps/docs/src/code/python/basics/fs_write_bytes.py b/apps/docs/src/code/python/basics/fs_write_bytes.pynew file mode 100644index 000000000..0bbd57ab7--- /dev/null+++ b/apps/docs/src/code/python/basics/fs_write_bytes.py@@ -0,0 +1,21 @@+import asyncio+from os import getenv+from e2b import Session++E2B_API_KEY = getenv("E2B_API_KEY")++async def main():+ session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)++ content_in_bytes = bytearray(b"Hello world")++ # `write_bytes` will write bytearray to a file inside the playground.+ await session.filesystem.write_bytes('/file', content_in_bytes) # $HighlightLine++ # We can read the file back to verify the content+ file_content = await session.filesystem.read('/file')+ print(file_content)++ await session.close()++asyncio.run(main())diff --git a/apps/docs/src/code/python/poetry.lock b/apps/docs/src/code/python/poetry.lockindex 48fd85d97..4af857e9f 100644--- a/apps/docs/src/code/python/poetry.lock+++ b/apps/docs/src/code/python/poetry.lock@@ -249,18 +249,19 @@ files = [[[package]]name = "e2b"-version = "0.2.5"+version = "0.3.0"description = "E2B SDK that give agents cloud environments"optional = falsepython-versions = ">=3.8,<4.0"files = [- {file = "e2b-0.2.5-py3-none-any.whl", hash = "sha256:e35c52df927b4d99ac12cae7bdff7f8b1dcd6f49a6c842b082c7e29afe2f81c4"},- {file = "e2b-0.2.5.tar.gz", hash = "sha256:6fd6f206803c53570d415a6fb1c5802bab2d38683649598953312b2d62242e42"},+ {file = "e2b-0.3.0-py3-none-any.whl", hash = "sha256:d080f04a6d4d6355e94942e23bb859508049db11586b4dcb0b217eeddefa3ed4"},+ {file = "e2b-0.3.0.tar.gz", hash = "sha256:431a44f81730bcbb5303d8f344fce81834ed12c13f420197c803b4db58950d49"},][package.dependencies]aenum = ">=3.1.11"aiohttp = ">=3.8.4"+async-timeout = ">=4.0.3,<5.0.0"janus = ">=1.0.0,<2.0.0"jsonrpcclient = ">=4.0.3,<5.0.0"pydantic = ">=1.10.5,<2.0.0"@@ -733,4 +734,4 @@ multidict = ">=4.0"[metadata]lock-version = "2.0"python-versions = "^3.8"-content-hash = "964933943afc90b6b2122dbe7704dd813461efd9002ba48c44e6890deaf24258"+content-hash = "cf42485158102a9dea358ba35ef47a53b9e327012912c97f78fbccb185d31b3c"diff --git a/apps/docs/src/code/python/pyproject.toml b/apps/docs/src/code/python/pyproject.tomlindex 65402fb0c..ac47bb851 100644--- a/apps/docs/src/code/python/pyproject.toml+++ b/apps/docs/src/code/python/pyproject.toml@@ -7,7 +7,7 @@ readme = "README.md"[tool.poetry.dependencies]python = "^3.8"-e2b = "^0.2.2"+e2b = "^0.3.0"[build-system]diff --git a/apps/docs/src/components/Navigation.tsx b/apps/docs/src/components/Navigation.tsxindex 0b49b85fa..51f54736d 100644--- a/apps/docs/src/components/Navigation.tsx+++ b/apps/docs/src/components/Navigation.tsx@@ -332,8 +332,26 @@ export const navigation = [title: 'Running Processes',href: '/playgrounds/process',},- // { icon: <FileUp strokeWidth={1} size={20}/>, title: 'Upload Files', href: '/playgrounds/upload' },- // { icon: <FileDown strokeWidth={1} size={20}/>, title: 'Download Files', href: '/playgrounds/download' },+ // {+ // icon: (+ // <FileUp+ // strokeWidth={1}+ // size={20}+ // />+ // ),+ // title: 'Upload Files',+ // href: '/playgrounds/upload',+ // },+ // {+ // icon: (+ // <FileDown+ // strokeWidth={1}+ // size={20}+ // />+ // ),+ // title: 'Download Files',+ // href: '/playgrounds/download',+ // },{icon: (<Bugdiff --git a/package.json b/package.jsonindex ef4de8bec..9b3d1af6a 100644--- a/package.json+++ b/package.json@@ -5,7 +5,8 @@"scripts": {"version": "changeset version && npm run postVersion --workspaces --if-present","publish": "changeset publish && npm run postPublish --workspaces --if-present",- "test": "npm run test --workspaces --if-present"+ "test": "npm run test --workspaces --if-present",+ "dev:docs": "npm --prefix apps/docs run dev"},"workspaces": ["packages/*"@@ -26,4 +27,4 @@"prettier": "^3.0.3","prettier-plugin-tailwindcss": "^0.5.4"}-}+}\ No newline at end of file