Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Oct 15, 2024
2 parents ab0ba2d + 3d9208c commit b758bb6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
68 changes: 61 additions & 7 deletions apps/web/src/app/(docs)/docs/legacy/guide/beta-migration/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ The latest beta versions you should install can be found in NPM/PyPi release his
- [Creating sandbox](#creating-sandbox)
- [Modifying sandbox timeout](#modifying-sandbox-timeout)
- [Reconnecting](#reconnecting)
- [Uploading data and creating files in sandbox](#uploading-data-and-creating-files-in-sandbox)
- [Downloading files and reading files in sandbox](#downloading-files-and-reading-files-in-sandbox)
- [Writing files to sandbox](#writing-files-to-sandbox)
- [Reading files from sandbox](#reading-files-from-sandbox)
- [Uploading data to sandbox](#uploading-data-to-sandbox)
- [Downloading files from sandbox](#downloading-files-from-sandbox)
- [Running processes](#running-processes)
- [Watching for files' changes](#watching-for-files-changes)
- [Accessing sandbox ID](#accessing-sandbox-id)
Expand All @@ -24,10 +26,10 @@ The latest beta versions you should install can be found in NPM/PyPi release his
- [Timeouts](#timeouts)
- [Listing sandboxes](#listing-sandboxes)
- [Getting sandbox url](#getting-sandbox-url)
- [Code Interpreter SDK changes](#code-interpreter-sdk-changes)
- [Code Interpreter SDK changes](#code-interpreter-sdk-changes)
- [Executing code](#executing-code)
- [Custom template](#custom-template)
- [Python Async](#python-async)
- [Python Async](#python-async)
- [Watching for files' changes in async Python SDK](#watching-for-files-changes-in-async-python-sdk)
- [Running background commands in async Python SDK](#running-background-commands-in-async-python-sdk)

Expand Down Expand Up @@ -164,7 +166,59 @@ existing_sandbox = Sandbox.connect(sandbox.sandbox_id)
```
</CodeGroup>

## Uploading data and creating files in sandbox
## 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.

<CodeGroup isRunnable={false}>
```js
import Sandbox from 'e2b'

// Before
// await sandbox.filesystem.write('/hello.txt', 'Hello World!')

// Now
await sandbox.files.write('/path/in/sandbox', 'Hello World!')
```
```python
from e2b import Sandbox

# Before
# sandbox.filesystem.write("/hello.txt", "Hello World!")

# Now
sandbox.files.write("/path/in/sandbox", "Hello World!")
```
</CodeGroup>

## 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.

<CodeGroup isRunnable={false}>
```js
import Sandbox from 'e2b'

// Before
//const content = await sandbox.downloadFile('/path/in/sandbox')

// Now
const content = await sandbox.files.read('/path/in/sandbox')
```
```python
from e2b import Sandbox

# Before
# content = sandbox.download_file("/path/in/sandbox")

# Now
content = sandbox.files.read("/path/in/sandbox")
```
</CodeGroup>

## 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.
Expand Down Expand Up @@ -194,7 +248,7 @@ with open("path/to/local/file", "rb") as file:
```
</CodeGroup>

## Downloading files and reading files in sandbox
## 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.
Expand All @@ -213,7 +267,7 @@ const content = await sandbox.files.read('/path/in/sandbox')
from e2b import Sandbox

# Before
# content = sandbox.download_file('/path/in/sandbox')
# content = sandbox.download_file("/path/in/sandbox")

# Now
content = sandbox.files.read("/path/in/sandbox")
Expand Down
10 changes: 5 additions & 5 deletions apps/web/src/app/(docs)/docs/legacy/hello-world/js/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Usually, all you need from the model is just support for tool use. If the LLM do
Create the `model.ts` file and paste the following code.
<CodeGroup isFileName title="model.ts" isRunnable={false}>
```ts
import { Tool } from '@anthropic-ai/sdk/src/resources/beta/tools'
import { Anthropic } from '@anthropic-ai/sdk'

export const MODEL_NAME = 'claude-3-opus-20240229'

Expand All @@ -67,7 +67,7 @@ you are a python data scientist. you are given tasks to complete and you run pyt
- you can run any python code you want, everything is running in a secure sandbox environment.
`

export const tools: Tool[] = [
export const tools: Anthropic.Tool[] = [
{
name: 'execute_python',
description: 'Execute python code in a Jupyter notebook cell and returns any result, stdout, stderr, display_data, and error.',
Expand Down Expand Up @@ -139,7 +139,7 @@ ANTHROPIC_API_KEY="anthropic-api-key"

<CodeGroup isRunnable={false}>
```bash {{ language: 'python' }}
npm i @anthropic-ai/sdk
npm i @anthropic-ai/sdk@0.28.0
```
</CodeGroup>

Expand All @@ -166,7 +166,7 @@ const anthropic = new Anthropic()
async function chat(codeInterpreter: CodeInterpreter, userMessage: string): Promise<Execution | undefined> {
console.log('Waiting for Claude...')

const msg = await anthropic.beta.tools.messages.create({
const msg = await anthropic.messages.create({
model: MODEL_NAME,
system: SYSTEM_PROMPT,
max_tokens: 4096,
Expand Down Expand Up @@ -305,4 +305,4 @@ The chart got saved in the `chart.png` file and it should look similar to this:
className="rounded w-full"
alt="Chart visualizing distribution height of men"
unoptimized
/>
/>
6 changes: 3 additions & 3 deletions apps/web/src/app/(docs)/docs/legacy/hello-world/py/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ ANTHROPIC_API_KEY="anthropic-api-key"

<CodeGroup isRunnable={false}>
```bash {{ language: 'python' }}
pip install anthropic
pip install anthropic==0.35.0
```
</CodeGroup>

Expand All @@ -157,7 +157,7 @@ client = Anthropic()
def chat(code_interpreter: CodeInterpreter, user_message: str) -> Tuple[List[Result], Logs]:
print(f"\n{'='*50}\nUser Message: {user_message}\n{'='*50}")

message = client.beta.tools.messages.create(
message = client.messages.create(
model=MODEL_NAME,
system=SYSTEM_PROMPT,
max_tokens=4096,
Expand Down Expand Up @@ -250,4 +250,4 @@ The chart was saved in the `chart.png` file and it should look similar to this:
className="rounded w-full"
alt="Chart visualizing distribution height of men"
unoptimized
/>
/>
4 changes: 2 additions & 2 deletions apps/web/src/code/python/reconnect/reconnect_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
sandboxID = sandbox.id

# Keep the sandbox alive for 2 minutes
sandbox.keep_alive(60 * 60) # $HighlightLine
sandbox.keep_alive(60 * 2) # $HighlightLine

# Close the sandbox. Even if we close the sandbox, it will stay alive, because we explicitly called keep_alive().
sandbox.close()

# Do something else...
time.sleep(60)
time.sleep(60)
1 change: 1 addition & 0 deletions templates/base/e2b.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# const sandbox = await Sandbox.create({ template: 'base' })

team_id = "460355b3-4f64-48f9-9a16-4442817f79f5"
memory_mb = 512
dockerfile = "e2b.Dockerfile"
template_name = "base"
template_id = "rki5dems9wqfm4r03t7g"

0 comments on commit b758bb6

Please sign in to comment.