From fea9f65aa1edad53d66d21f1c4c346608c2514d1 Mon Sep 17 00:00:00 2001 From: Vasek Mlejnsky Date: Mon, 30 Sep 2024 15:01:56 -0700 Subject: [PATCH 1/6] Update migration docs --- .../(docs)/docs/guide/beta-migration/page.mdx | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/apps/web/src/app/(docs)/docs/guide/beta-migration/page.mdx b/apps/web/src/app/(docs)/docs/guide/beta-migration/page.mdx index c5f71b909..ce32eb652 100644 --- a/apps/web/src/app/(docs)/docs/guide/beta-migration/page.mdx +++ b/apps/web/src/app/(docs)/docs/guide/beta-migration/page.mdx @@ -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) @@ -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) @@ -164,7 +166,59 @@ existing_sandbox = Sandbox.connect(sandbox.sandbox_id) ``` -## 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. + + +```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!") +``` + + +## 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. + + +```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") +``` + + +## 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. @@ -194,7 +248,7 @@ with open("path/to/local/file", "rb") as file: ``` -## 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. @@ -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") From 17a00099194a7bfd51fb11d2e521af8688bf6d17 Mon Sep 17 00:00:00 2001 From: James Murdza Date: Sat, 5 Oct 2024 12:53:24 -0700 Subject: [PATCH 2/6] Fix helloWorld.ts example for latest Anthropic SDK --- apps/web/src/app/(docs)/docs/hello-world/js/page.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/web/src/app/(docs)/docs/hello-world/js/page.mdx b/apps/web/src/app/(docs)/docs/hello-world/js/page.mdx index 0e650b5ef..9d71e345a 100644 --- a/apps/web/src/app/(docs)/docs/hello-world/js/page.mdx +++ b/apps/web/src/app/(docs)/docs/hello-world/js/page.mdx @@ -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. ```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' @@ -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.', @@ -166,7 +166,7 @@ const anthropic = new Anthropic() async function chat(codeInterpreter: CodeInterpreter, userMessage: string): Promise { 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, @@ -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 -/> \ No newline at end of file +/> From 7087d213102e67b12517a7e6e4f14f4aab1ca303 Mon Sep 17 00:00:00 2001 From: James Murdza Date: Sat, 5 Oct 2024 12:57:45 -0700 Subject: [PATCH 3/6] Fix hello_world.py example for latest Anthropic SDK --- apps/web/src/app/(docs)/docs/hello-world/py/page.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/app/(docs)/docs/hello-world/py/page.mdx b/apps/web/src/app/(docs)/docs/hello-world/py/page.mdx index 40bdda1f1..ef95e6d97 100644 --- a/apps/web/src/app/(docs)/docs/hello-world/py/page.mdx +++ b/apps/web/src/app/(docs)/docs/hello-world/py/page.mdx @@ -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, @@ -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 -/> \ No newline at end of file +/> From 85c1b87af82af399dbbb2bcbd00ea6eb43d1f27e Mon Sep 17 00:00:00 2001 From: James Murdza Date: Sat, 5 Oct 2024 13:14:26 -0700 Subject: [PATCH 4/6] Pin Anthropic SDK version in examples --- apps/web/src/app/(docs)/docs/hello-world/js/page.mdx | 2 +- apps/web/src/app/(docs)/docs/hello-world/py/page.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/app/(docs)/docs/hello-world/js/page.mdx b/apps/web/src/app/(docs)/docs/hello-world/js/page.mdx index 9d71e345a..58ebd6929 100644 --- a/apps/web/src/app/(docs)/docs/hello-world/js/page.mdx +++ b/apps/web/src/app/(docs)/docs/hello-world/js/page.mdx @@ -139,7 +139,7 @@ ANTHROPIC_API_KEY="anthropic-api-key" ```bash {{ language: 'python' }} -npm i @anthropic-ai/sdk +npm i @anthropic-ai/sdk@0.28.0 ``` diff --git a/apps/web/src/app/(docs)/docs/hello-world/py/page.mdx b/apps/web/src/app/(docs)/docs/hello-world/py/page.mdx index ef95e6d97..fc8b6198f 100644 --- a/apps/web/src/app/(docs)/docs/hello-world/py/page.mdx +++ b/apps/web/src/app/(docs)/docs/hello-world/py/page.mdx @@ -130,7 +130,7 @@ ANTHROPIC_API_KEY="anthropic-api-key" ```bash {{ language: 'python' }} -pip install anthropic +pip install anthropic==0.35.0 ``` From fd9a7f15524ea9a96dd24309cf60bb45946b71f8 Mon Sep 17 00:00:00 2001 From: Vasek Mlejnsky Date: Sat, 5 Oct 2024 14:09:39 -0700 Subject: [PATCH 5/6] Update reconnect_2.py --- apps/web/src/code/python/reconnect/reconnect_2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/code/python/reconnect/reconnect_2.py b/apps/web/src/code/python/reconnect/reconnect_2.py index e3ba516a3..fd02528a3 100644 --- a/apps/web/src/code/python/reconnect/reconnect_2.py +++ b/apps/web/src/code/python/reconnect/reconnect_2.py @@ -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) \ No newline at end of file +time.sleep(60) From 3d9208cbd3dd8e9433b975003726e42d8dffba79 Mon Sep 17 00:00:00 2001 From: Tomas Valenta Date: Mon, 7 Oct 2024 16:31:11 -0700 Subject: [PATCH 6/6] Fixate memory size of base template --- templates/base/e2b.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/base/e2b.toml b/templates/base/e2b.toml index 8941fa824..dd4477244 100644 --- a/templates/base/e2b.toml +++ b/templates/base/e2b.toml @@ -9,5 +9,6 @@ # import { Sandbox } from 'e2b' # const sandbox = await Sandbox.create({ template: 'rki5dems9wqfm4r03t7g' }) +memory_mb = 512 dockerfile = "e2b.Dockerfile" template_id = "rki5dems9wqfm4r03t7g"