Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Added docs for pre-signed URLs (#783)
Jiri Sveceny3d68fceffda2
diff --git a/apps/web/src/app/(docs)/docs/filesystem/download/page.mdx b/apps/web/src/app/(docs)/docs/filesystem/download/page.mdxindex d9f9de798..ef6eaeb5b 100644--- a/apps/web/src/app/(docs)/docs/filesystem/download/page.mdx+++ b/apps/web/src/app/(docs)/docs/filesystem/download/page.mdx@@ -26,3 +26,41 @@ with open('/local/path', 'w') as file:file.write(content)```</CodeGroup>+++## Download with pre-signed URL++Sometimes, you may want to let users from unauthorized environments, like a browser, download files from the sandbox.+For this use case, you can use pre-signed URLs to let users download files securely.++<CodeGroup>+```js+import fs from 'fs'+import { Sandbox } from '@e2b/code-interpreter'++// Start a secured sandbox (all operations must be authorized by default)+const sandbox = await Sandbox.create(template, { secure: true })++// Create a pre-signed URL for file download with a 10 second expiration+const publicUrl = sandbox.downloadUrl(+ 'demo.txt', {+ useSignature: true,+ useSignatureExpiration: 10_000, // optional+ },+)++// Download a file with a pre-signed URL (this can be used in any environment, such as a browser)+const res = await fetch(publicUrl)+const content = await res.text()+```+```python+from e2b import Sandbox++# Start a secured sandbox (all operations must be authorized by default)+sandbox = Sandbox(timeout=12_000, secure=True)++# Create a pre-signed URL for file download with a 10 second expiration+# The user only has to visit the URL to download the file, this also works in a browser.+signed_url = sbx.download_url(path="demo.txt", user="user", use_signature=True, use_signature_expiration=10_000)+```+</CodeGroup>diff --git a/apps/web/src/app/(docs)/docs/filesystem/upload/page.mdx b/apps/web/src/app/(docs)/docs/filesystem/upload/page.mdxindex b0d7877d7..5271861ed 100644--- a/apps/web/src/app/(docs)/docs/filesystem/upload/page.mdx+++ b/apps/web/src/app/(docs)/docs/filesystem/upload/page.mdx@@ -28,6 +28,51 @@ with open("path/to/local/file", "rb") as file:```</CodeGroup>+## Upload with pre-signed URL++Sometimes, you may want to let users from unauthorized environments, like a browser, upload files to the sandbox.+For this use case, you can use pre-signed URLs to let users upload files securely.++<CodeGroup>+```js+import fs from 'fs'+import { Sandbox } from '@e2b/code-interpreter'++// Start a secured sandbox (all operations must be authorized by default)+const sandbox = await Sandbox.create(template, { secure: true })++// Create a pre-signed URL for file upload with a 10 second expiration+const publicUploadUrl = sandbox.uploadUrl(+ 'demo.txt', {+ useSignature: true,+ useSignatureExpiration: 10_000, // optional+ },+)++// Upload a file with a pre-signed URL (this can be used in any environment, such as a browser)+const form = new FormData()+form.append('file', 'file content')++await fetch(publicUploadUrl, { method: 'POST', body: form })++// File is now available in the sandbox and you can read it+const content = fs.readFileSync('demo.txt')+```+```python+from e2b import Sandbox+import requests++# Start a secured sandbox (all operations must be authorized by default)+sandbox = Sandbox(timeout=12_000, secure=True)++# Create a pre-signed URL for file upload with a 10 second expiration+signed_url = sbx.upload_url(path="demo.txt", user="user", use_signature=True, use_signature_expiration=10_000)++form_data = {"file":"file content"}+requests.post(signed_url, data=form_data)+```+</CodeGroup>+## Upload directory / multiple files<CodeGroup>