Skip to content

Commit

Permalink
Docs (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlejva authored Oct 31, 2023
1 parent 6156bb1 commit 8532272
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 25 deletions.
1 change: 1 addition & 0 deletions apps/docs/src/app/getting-help/page.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Getting help

If you have any questions, issues, or feature requests, please reach out on of the following channels: {{ className: 'lead' }}
- Send us an email at [hello@e2b.dev](mailto:hello@e2b.dev)
- Talk to us on our [Discord server](https://discord.gg/U7KEcGErtQ)
- Open an issue on [our GitHub](https://github.com/e2b-dev/e2b)
- Reach out on [Twitter / X](https://twitter.com/e2b_dev)
9 changes: 9 additions & 0 deletions apps/docs/src/app/sandbox/download/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Download files from sandbox
Any file inside the sandbox can be downloaded using the `downloadFile`/`download_file` method.

## Use case for downloading files
For example, the download file method is useful for downloading any files produced by LLM. You can let LLM generate and execute code inside the sandbox.
This LLM-generated code might produce some files like charts, CSV files, or PDF file that you want to download to your machine.

<CodeGroupAutoload path="basics/download_file" isRunnable={false}/>

12 changes: 12 additions & 0 deletions apps/docs/src/app/sandbox/upload/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Upload files to sandbox
You can upload any file to the sandbox. This is useful if you want to let the LLM work with your files or files of your users. The file will be uploaded to the user's home directory with the same name. If a file with the same name already exists, it will be overwritten.

## Use case for uploading files
A popular workflow is for example to upload a CSV data file and then let the LLM generate and execute Python code that operates with the uploaded CSV file inside the sandbox. This way, you can essentially create your own AI data analyst or code interpreter.

<Note>
We support uploading files up to the 100MB at the moment. If you need to upload larger files, please [reach out to us](/getting-help).
</Note>

<CodeGroupAutoload path="basics/upload_file" isRunnable={false}/>

10 changes: 8 additions & 2 deletions apps/docs/src/app/sandbox/url/page.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Sandbox URL
Each sandbox is accessible from the internet via a unique URL of that sandbox.
Each sandbox has its own URL that you can use to connect to any service running inside the sandbox.

<CodeGroupAutoload path="basics/get_url" isRunnable={true} />
For example, you can start a server inside the sandbox and connect to it from your browser.

<CodeGroupAutoload path="basics/get_url" isRunnable={true} />


If you want to get an URL for a specific port inside the sanbdox, pass the port number to the `getHostname()`/`get_hostname()` method.
<CodeGroupAutoload path="basics/get_url_port" isRunnable={true} />
10 changes: 10 additions & 0 deletions apps/docs/src/code/js/basics/download_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Session } from '@e2b/sdk'
import fs from 'node:fs'

const session = await Session.create({ id: 'Nodejs' })

const buffer = await session.downloadFile('path/to/remote/file/inside/sandbox') // $HighlightLine
// Save file to local filesystem
fs.writeFileSync('path/to/local/file', buffer)

await session.close()
3 changes: 2 additions & 1 deletion apps/docs/src/code/js/basics/get_url_port.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Session } from '@e2b/sdk'

const session = await Session.create({ id: 'Nodejs' })

const url = session.getHostname(3000) // $HighlightLine
const openPort = 3000
const url = session.getHostname(openPort) // $HighlightLine
console.log('https://' + url)

await session.close()
23 changes: 23 additions & 0 deletions apps/docs/src/code/js/basics/upload_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Session } from '@e2b/sdk'
import fs from 'node:fs'

const session = await Session.create({ id: 'Nodejs' })

// If you're in the server environment
const filename = 'data.csv' // $HighlightLine
const fileBuffer = fs.readFileSync('path/to/local/file') // $HighlightLine
const remotePath = await session.uploadFile(fileBuffer, filename) // $HighlightLine

// If you're in the browser environment, you can use the Blob API
// const filename = 'data.csv'
// const CSV = [
// '"1","val1","val2","val3","val4"',
// '"2","val1","val2","val3","val4"',
// '"3","val1","val2","val3","val4"'
// ].join('\n');
// const fileBlob = new Blob([csv], { type: 'text/csv' })
// const remotePath = await session.uploadFile(fileBlob, 'data.csv')

console.log(`The file was uploaded to '${remotePath}' path inside the sandbox `)

await session.close()
10 changes: 10 additions & 0 deletions apps/docs/src/code/python/basics/download_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from e2b import Session

session = Session.create(id="Nodejs")

file_in_bytes = session.download_file('path/to/remote/file/inside/sandbox') # $HighlightLine
# Save file to local filesystem
with open('path/to/local/file', 'wb') as f: # $HighlightLine
f.write(file_in_bytes) # $HighlightLine

session.close()
2 changes: 2 additions & 0 deletions apps/docs/src/code/python/basics/get_url.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from e2b import Session

session = Session.create(id="Nodejs")

url = session.get_hostname() # $HighlightLine
print("https://" + url)

session.close()
3 changes: 2 additions & 1 deletion apps/docs/src/code/python/basics/get_url_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

session = Session.create(id="Nodejs")

url = session.get_hostname(3000) # $HighlightLine
open_port = 3000
url = session.get_hostname(open_port) # $HighlightLine
print("https://" + url)

session.close()
8 changes: 8 additions & 0 deletions apps/docs/src/code/python/basics/upload_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from e2b import Session

session = Session.create(id="Nodejs")

with open('path/to/local/file', 'rb') as f:
remote_path = session.upload_file(f) # $HighlightLine

session.close()
42 changes: 22 additions & 20 deletions apps/docs/src/components/Navigation/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
Hammer,
Cpu,
Link,
FileUp,
FileDown,
} from 'lucide-react'

export const routes = [
Expand Down Expand Up @@ -148,26 +150,6 @@ export const routes = [
// title: 'Executing Code',
// href: '/sandbox/execute',
// },
// {
// icon: (
// <FileUp
// strokeWidth={1}
// size={20}
// />
// ),
// title: 'Upload Files',
// href: '/sandbox/upload',
// },
// {
// icon: (
// <FileDown
// strokeWidth={1}
// size={20}
// />
// ),
// title: 'Download Files',
// href: '/sandbox/download',
// },
{
icon: (
<Folder
Expand Down Expand Up @@ -208,6 +190,26 @@ export const routes = [
title: 'Sandbox URL',
href: '/sandbox/url',
},
{
icon: (
<FileUp
strokeWidth={1}
size={20}
/>
),
title: 'Upload Files',
href: '/sandbox/upload',
},
{
icon: (
<FileDown
strokeWidth={1}
size={20}
/>
),
title: 'Download Files',
href: '/sandbox/download',
},
{
icon: (
<Timer
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/typography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ export default function typographyStyles({ theme }: PluginUtils) {

// Inline elements
a: {
color: 'var(--tw-prose-links)',
// color: 'var(--tw-prose-links)',
color: theme('colors.brand.500'),
textDecoration: `underline ${theme('colors.brand.500 / 0.3')}`,
textDecorationThickness: '2px',
fontWeight: '500',
Expand Down

1 comment on commit 8532272

@vercel
Copy link

@vercel vercel bot commented on 8532272 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

e2b-docs – ./apps/docs

e2b-docs.vercel.app
e2b-docs-e2b.vercel.app
e2b-docs-git-main-e2b.vercel.app

Please sign in to comment.