Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add basic python code snippets

Vasek Mlejnskyc9b1e9de21e0
diff --git a/apps/docs/src/app/getting-started/basics/page.mdx b/apps/docs/src/app/getting-started/basics/page.mdx
index 768b83e18..dffc1eb03 100644
--- a/apps/docs/src/app/getting-started/basics/page.mdx
+++ b/apps/docs/src/app/getting-started/basics/page.mdx
@@ -3,109 +3,80 @@ export const metadata = {
description: 'SDK Usage',
}
+export const sections = [
+ { title: 'Create Playground', id: 'create-playground' },
+ { title: 'Use Filesystem', id: 'filesystem' },
+ // { title: 'Run Commands', id: 'filesystem' },
+]
+
# Basic Usage
Following code snippets should get you going fast with our SDK.
For more real-life scenarios head to the [Examples section](./examples/overview).
-### Initialize new cloud environment session
+## Create Playground
<CodeGroup>
-```python
-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()
+```python {{ language: 'python', snippet: 'python/basics/init.py' }}
+```
+</CodeGroup>
-...
+## Filesystem
-# Close the session after you are done
-await session.close()
+### List directory
+<CodeGroup>
+```python {{ language: 'python', snippet: 'python/basics/fs_ls.py' }}
```
</CodeGroup>
-### Use filesystem inside cloud environment
+### Create directory
<CodeGroup>
-```python
-# 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()
+```python {{ language: 'python', snippet: 'python/basics/fs_mkdir.py' }}
```
</CodeGroup>
-### Start process inside cloud environment
+### Write to file
<CodeGroup>
-```python
-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()
+```python {{ language: 'python', snippet: 'python/basics/fs_write.py' }}
+```
+</CodeGroup>
-# Wait for process to finish
-await proc.finished
+### Read file
+<CodeGroup>
+```python {{ language: 'python', snippet: 'python/basics/fs_write.py' }}
```
</CodeGroup>
-### Create interactive terminal inside cloud environment
+### Watch directory for changes
<CodeGroup>
-```python
-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",
-)
+```python {{ language: 'python', snippet: 'python/basics/fs_watch.py' }}
+```
+</CodeGroup>
-await term.send_data("echo 1\n")
+## Process
-await term.resize(80, 30)
+### Start process
+<CodeGroup>
+```python {{ language: 'python', snippet: 'python/basics/process_start.py' }}
+```
+</CodeGroup>
-print(term.terminal_id)
+### Stop process
+<CodeGroup>
+```python {{ language: 'python', snippet: 'python/basics/process_stop.py' }}
+```
+</CodeGroup>
-await term.kill()
+### Stream stdout
+<CodeGroup>
+```python {{ language: 'python', snippet: 'python/basics/process_stream_stdout.py' }}
```
</CodeGroup>
-### Get public hostname for an exposed port inside cloud environment
+### Stream stderr
<CodeGroup>
-```python
-# Get hostname for port 3000. The hostname is without the protocol (http://).
-hostname = session.get_hostname(3000)
+```python {{ language: 'python', snippet: 'python/basics/process_stream_stderr.py' }}
```
-</CodeGroup>
\ No newline at end of file
+</CodeGroup>
+
+{/* ### Send input to stdin */}
\ No newline at end of file
diff --git a/apps/docs/src/app/getting-started/installation/page.mdx b/apps/docs/src/app/getting-started/installation/page.mdx
index b340bda6d..10be577b8 100644
--- a/apps/docs/src/app/getting-started/installation/page.mdx
+++ b/apps/docs/src/app/getting-started/installation/page.mdx
@@ -9,7 +9,11 @@ We offer SDKs for **JavaScript**, **TypeScript**, and **Python**. The SDKs are r
You can install them using the following commands:
<CodeGroup>
-```bash {{ language: 'js', title: 'JavaScript/TypeScript' }}
+```bash {{ language: 'js' }}
+npm install @e2b/sdk
+```
+
+```bash {{ language: 'ts' }}
npm install @e2b/sdk
```
@@ -18,4 +22,4 @@ pip install e2b
```
</CodeGroup>
-Once installed head over to the [Basics](/getting-started/basics) or [Examples](/examples/overview) section. {{ className: 'lead' }}
+Once installed head over to the [Basics](/getting-started/basics) section. {{ className: 'lead' }}
diff --git a/apps/docs/src/app/page.mdx b/apps/docs/src/app/page.mdx
index 9a3341dc5..e12ca6539 100644
--- a/apps/docs/src/app/page.mdx
+++ b/apps/docs/src/app/page.mdx
@@ -40,8 +40,12 @@ Our SDK works with any AI agent (no matter what framework you're using), and wit
## Quickstart Example
<CodeGroup>
-```bash {{ language: 'js', title: 'JavaScript & TypeScript' }}
-npm install @e2b/sdk
+```bash {{ language: 'js' }}
+npm i @e2b/sdk
+```
+
+```bash {{ language: 'ts' }}
+npm i @e2b/sdk
```
```bash {{ language: 'python' }}
@@ -50,9 +54,12 @@ pip install e2b
</CodeGroup>
<CodeGroup>
-```ts {{ language: 'js', title: 'JavaScript & TypeScript', snippet: 'quickstart.js'}}
+```js {{ language: 'js', snippet: 'js/quickstart.js' }}
+```
+
+```ts {{ language: 'ts', snippet: 'ts/quickstart.ts' }}
```
-```py {{ language: 'python', snippet: 'quickstart.py'}}
+```py {{ language: 'python', snippet: 'python/fs_ls.py'}}
```
</CodeGroup>
diff --git a/apps/docs/src/code/js/quickstart.js b/apps/docs/src/code/js/quickstart.js
index 7e7b05788..1b8085af4 100644
--- a/apps/docs/src/code/js/quickstart.js
+++ b/apps/docs/src/code/js/quickstart.js
@@ -1 +1,5 @@
-import { Session } from '@e2b/sdk'
\ No newline at end of file
+import { Session } from '@e2b/sdk'
+
+const s = await Session.create({
+ id: 'Nodejs',
+})
\ No newline at end of file
diff --git a/apps/docs/src/code/ts/tsconfig.json b/apps/docs/src/code/ts/tsconfig.json
index e075f973c..7f2f9e445 100644
--- a/apps/docs/src/code/ts/tsconfig.json
+++ b/apps/docs/src/code/ts/tsconfig.json
@@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
+ "target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
@@ -25,8 +25,9 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
- "module": "commonjs", /* Specify what module code is generated. */
+ "module": "esnext", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
+ "moduleResolution": "nodenext",
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
diff --git a/apps/docs/src/components/Navigation.jsx b/apps/docs/src/components/Navigation.jsx
index e5c5ae861..b11cc9b47 100644
--- a/apps/docs/src/components/Navigation.jsx
+++ b/apps/docs/src/components/Navigation.jsx
@@ -75,7 +75,7 @@ function VisibleSectionHighlight({ group, pathname }) {
? Math.max(1, visibleSections.length) * itemHeight
: itemHeight
let top =
- group.links.findIndex((link) => link.href === pathname) * itemHeight +
+ group.links.findIndex((link) => `/docs${link.href}` === pathname) * itemHeight +
firstVisibleSectionIndex * itemHeight
return (
@@ -93,7 +93,7 @@ function VisibleSectionHighlight({ group, pathname }) {
function ActivePageMarker({ group, pathname }) {
let itemHeight = remToPx(2)
let offset = remToPx(0.25)
- let activePageIndex = group.links.findIndex((link) => link.href === pathname)
+ let activePageIndex = group.links.findIndex((link) => `/docs${link.href}` === pathname)
let top = offset + activePageIndex * itemHeight
return (
@@ -119,7 +119,7 @@ function NavigationGroup({ group, className }) {
)
let isActiveGroup =
- group.links.findIndex((link) => link.href === pathname) !== -1
+ group.links.findIndex((link) => `/docs${link.href}` === pathname) !== -1
return (
<li className={clsx('relative mt-6', className)}>
@@ -147,11 +147,11 @@ function NavigationGroup({ group, className }) {
<ul role="list" className="border-l border-transparent">
{group.links.map((link) => (
<motion.li key={link.href} layout="position" className="relative">
- <NavLink href={link.href} active={link.href === pathname} isFontMono={link.isFontMono}>
+ <NavLink href={link.href} active={`/docs${link.href}` === pathname} isFontMono={link.isFontMono}>
{link.title}
</NavLink>
<AnimatePresence mode="popLayout" initial={false}>
- {link.href === pathname && sections.length > 0 && (
+ {`/docs${link.href}` === pathname && sections.length > 0 && (
<motion.ul
role="list"
initial={{ opacity: 0 }}
@@ -199,7 +199,7 @@ export const navigation = [
links: [
{ title: 'Installation', href: '/getting-started/installation' },
{ title: 'Basics', href: '/getting-started/basics' },
- { title: 'Use with AI Agents & Copilots', href: '/getting-started/how-to' },
+ // { title: 'Use with AI Agents & Copilots', href: '/getting-started/how-to' },
],
},
// {
@@ -213,6 +213,7 @@ export const navigation = [
// {
// title: 'Examples',
// links: [
+ // { title: 'Dynamically install dependencies', href: '/examples/deps' },
// { title: 'Clone GitHub Repository', href: '/examples/clone-repo' },
// { title: 'Run Any Code', href: '/examples/run-code' },
// { title: 'Get Output From Linter', href: '/examples/linter' },
@@ -244,13 +245,14 @@ export const navigation = [
// {
// title: 'SDK Reference',
// links: [
- // { title: 'E2B', href: '/reference/e2b', isFontMono: true },
- //
+ // { title: 'E2B', href: '/reference/e2b', isFontMono: true },
+
// Primitives
// { title: 'e2b.process', href: '/reference/python/process', isFontMono: true },
// { title: 'e2b.filesystem', href: '/reference/python/filesystem', isFontMono: true },
// { title: 'e2b.http', href: '/reference/python/http', isFontMono: true },
- //
+ // { title: 'e2b.code', href: '/reference/python/code', isFontMono: true },
+
// High-level modules
// { title: 'e2b.code', href: '/reference/code', isFontMono: true },
// { title: 'e2b.browser', href: '/reference/browser', isFontMono: true },
diff --git a/apps/docs/src/mdx/remark.mjs b/apps/docs/src/mdx/remark.mjs
index 78cb4af4f..15603e9fc 100644
--- a/apps/docs/src/mdx/remark.mjs
+++ b/apps/docs/src/mdx/remark.mjs
@@ -25,7 +25,7 @@ function loadFileSnippet() {
if (snippet && node.value === "") {
fileLoadingPromises.push((async () => {
- const file = path.resolve(`./src/snippets/${snippetFileName}`)
+ const file = path.resolve(`./src/code/${snippetFileName}`)
const content = await readFile(file, 'utf8')
node.value = content
})())
diff --git a/apps/docs/src/snippets/quickstart.js b/apps/docs/src/snippets/quickstart.js
deleted file mode 100644
index da19c4fdf..000000000
--- a/apps/docs/src/snippets/quickstart.js
+++ /dev/null
@@ -1,4 +0,0 @@
-import { Session, Env } from '@e2b/sdk'
-const session = await Session.create({ id: 'Nodejs' })
-
-await session.filesystem.write('/hello.txt', 'Hello AI Agents!')
\ No newline at end of file
diff --git a/apps/docs/src/snippets/quickstart.py b/apps/docs/src/snippets/quickstart.py
deleted file mode 100644
index 35e82f780..000000000
--- a/apps/docs/src/snippets/quickstart.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import asyncio
-from e2b import Session
-
-async def main():
- session = await Session.create(id="Nodejs")
- await session.filesystem.write('/hello.txt', 'Hello AI Agents!')
-
-asyncio.new_event_loop().run_until_complete(main())
\ No newline at end of file