Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from e2b-dev:main #123

Merged
merged 42 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b2e80e1
Added multi-file write support
0div Oct 4, 2024
9e6bc17
address PR comments
0div Oct 4, 2024
966f0c7
[WIP] Cleanup
ValentaTomas Oct 5, 2024
eda88d0
address PR comments
0div Oct 7, 2024
a2d4ad7
boyscouting: fix some docstrings
0div Oct 7, 2024
a379a58
Add multi-file write support for python-sdk sync
0div Oct 7, 2024
608ef45
Use `@overload`
0div Oct 8, 2024
68ac038
merge beta
0div Oct 8, 2024
f010211
adapt multi file write tests for nested dirs
0div Oct 8, 2024
fbc4af4
allow passing empty array of files in python-sdk
0div Oct 8, 2024
2afb6d1
allow passing empty array of files in js-sdk
0div Oct 8, 2024
68e5efa
address PR comments
0div Oct 9, 2024
365af43
add extra tests to sandbox_sync write
0div Oct 9, 2024
7767d8f
updated js-sdk tests to check empty path behavior
0div Oct 9, 2024
f5cd1c0
add multifile upload to sanbox_async
0div Oct 9, 2024
834f84c
merge beta
0div Oct 10, 2024
2956a6e
better error messages in python-sdk
0div Oct 10, 2024
c277f9f
better error messages in js-sdk
0div Oct 10, 2024
86262f1
docstring for dataclass
0div Oct 10, 2024
97d0cc1
merge main
0div Dec 12, 2024
cf262ae
fix errors.ts comment
0div Dec 12, 2024
4ca2414
fixed typing syntax and watch tests
0div Dec 12, 2024
93dc1f9
update docs
0div Dec 12, 2024
741b329
add minor changeset
0div Dec 12, 2024
bbeeb04
upadte upload docs and improve read-write-docs
0div Dec 12, 2024
0e2a684
fix indentation in upload docs
0div Dec 13, 2024
b867fe4
Update apps/web/src/app/(docs)/docs/filesystem/read-write/page.mdx
0div Dec 13, 2024
e730810
Update apps/web/src/app/(docs)/docs/filesystem/read-write/page.mdx
0div Dec 13, 2024
d3b99fe
Update apps/web/src/app/(docs)/docs/filesystem/upload/page.mdx
0div Dec 13, 2024
424baec
Update apps/web/src/app/(docs)/docs/filesystem/upload/page.mdx
0div Dec 13, 2024
e73ad23
Update apps/web/src/app/(docs)/docs/filesystem/upload/page.mdx
0div Dec 13, 2024
d0fc09a
Update apps/web/src/app/(docs)/docs/filesystem/upload/page.mdx
0div Dec 13, 2024
1708cc0
Update apps/web/src/app/(docs)/docs/filesystem/upload/page.mdx
0div Dec 13, 2024
502c414
remove WriteData type in js-sdk
0div Dec 13, 2024
724fbc6
remove WriteData type in python-sdk
0div Dec 13, 2024
43f3c12
Update apps/web/src/app/(docs)/docs/filesystem/read-write/page.mdx
0div Mar 18, 2025
a8e88de
fix merge conflict with main
0div Mar 18, 2025
b3fe5e6
Add multi-file write support to the js and python sdks (#451)
0div Mar 19, 2025
ad73fab
Include build ID output for debugging purposes (#616)
r33drichards Mar 19, 2025
d26ff43
Fix release test for multi-file write support (#615)
0div Mar 19, 2025
82f1ba8
Add changeset (#618)
r33drichards Mar 19, 2025
60ece87
Run tests on prs to avoid broken builds (#619)
r33drichards Mar 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/new-berries-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@e2b/python-sdk': minor
'e2b': minor
---

the Filesytem write method is overloaded to also allow passing in an array of files
6 changes: 6 additions & 0 deletions .changeset/weak-radios-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@e2b/cli': patch
'e2b': patch
---

bump version for https://github.com/e2b-dev/E2B/commit/d26ff435d6c8a1e9dcb090d09a2879d8dc94a1ea
5 changes: 5 additions & 0 deletions .changeset/weak-rice-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2b/cli': patch
---

log build id with sandbox id
3 changes: 3 additions & 0 deletions .github/workflows/cli_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Test CLI

on:
workflow_call:
pull_request:
branches:
- main

permissions:
contents: read
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/js_sdk_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
secrets:
E2B_API_KEY:
required: true
pull_request:
branches:
- main

permissions:
contents: read
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/python_sdk_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
secrets:
E2B_API_KEY:
required: true
pull_request:
branches:
- main

permissions:
contents: read
Expand Down
34 changes: 31 additions & 3 deletions apps/web/src/app/(docs)/docs/filesystem/read-write/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Reading files

You can read files from the sandbox filesystem using the `files.reado()` method.
You can read files from the sandbox filesystem using the `files.read()` method.

<CodeGroup>
```js
Expand All @@ -18,20 +18,48 @@ file_content = sandbox.files.read('/path/to/file')
```
</CodeGroup>

## Writing files
## Writing single files

You can write files to the sandbox filesystem using the `files.write()` method.
You can write single files to the sandbox filesystem using the `files.write()` method.

<CodeGroup>
```js
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create()

await sandbox.files.write('/path/to/file', 'file content')
```
```python
from e2b_code_interpreter import Sandbox

sandbox = Sandbox()

await sandbox.files.write('/path/to/file', 'file content')
```
</CodeGroup>

## Writing multiple files

You can also write multiple files to the sandbox filesystem using the `files.write()` method.

<CodeGroup>
```js
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create()

await sandbox.files.write([
{ path: '/path/to/a', data: 'file content' },
{ path: '/another/path/to/b', data: 'file content' }
])
```
```python
from e2b_code_interpreter import Sandbox

sandbox = Sandbox()

await sandbox.files.write([
{ "path": "/path/to/a", "data": "file content" },
{ "path": "another/path/to/b", "data": "file content" }
])
```
</CodeGroup>
87 changes: 86 additions & 1 deletion apps/web/src/app/(docs)/docs/filesystem/upload/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

You can upload data to the sandbox using the `files.write()` method.

## Upload single file

<CodeGroup>
```js
import fs from 'fs'
Expand All @@ -22,6 +24,89 @@ sandbox = Sandbox()
# Read file from local filesystem
with open("path/to/local/file", "rb") as file:
# Upload file to sandbox
sandbox.files.write("/path/in/sandbox", file)
sandbox.files.write("/path/in/sandbox", file)
```
</CodeGroup>

## Upload directory / multiple files

<CodeGroup>
```js
const fs = require('fs');
const path = require('path');

import { Sandbox } from '@e2b/code-interpreter'

const sandbox = await Sandbox.create()

// Read all files in the directory and store their paths and contents in an array
const readDirectoryFiles = (directoryPath) => {
// Read all files in the local directory
const files = fs.readdirSync(directoryPath);

// Map files to objects with path and data
const filesArray = files
.filter(file => {
const fullPath = path.join(directoryPath, file);
// Skip if it's a directory
return fs.statSync(fullPath).isFile();
})
.map(file => {
const filePath = path.join(directoryPath, file);

// Read the content of each file
return {
path: filePath,
data: fs.readFileSync(filePath, 'utf8')
};
});

return filesArray;
};

// Usage example
const files = readDirectoryContents('/local/dir');
console.log(files);
// [
// { path: '/local/dir/file1.txt', data: 'File 1 contents...' },
// { path: '/local/dir/file2.txt', data: 'File 2 contents...' },
// ...
// ]

await sandbox.files.write(files)
```
```python
import os
from e2b_code_interpreter import Sandbox

sandbox = Sandbox()

def read_directory_files(directory_path):
files = []

# Iterate through all files in the directory
for filename in os.listdir(directory_path):
file_path = os.path.join(directory_path, filename)

# Skip if it's a directory
if os.path.isfile(file_path):
# Read file contents in binary mode
with open(file_path, "rb") as file:
files.append({
'path': file_path,
'data': file.read()
})

return files

files = read_directory_files("/local/dir")
print(files)
# [
# {"'path": "/local/dir/file1.txt", "data": "File 1 contents..." },
# { "path": "/local/dir/file2.txt", "data": "File 2 contents..." },
# ...
# ]

sandbox.files.write(files)
```
</CodeGroup>
2 changes: 1 addition & 1 deletion packages/cli/src/commands/template/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export const buildCommand = new commander.Command('build')
console.log(
`> Triggered build for the sandbox template ${asFormattedSandboxTemplate(
template
)} `
)} with build ID: ${template.buildID}`
)

console.log('Waiting for build to finish...')
Expand Down
25 changes: 11 additions & 14 deletions packages/js-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
export { ApiClient } from './api'
export type { components, paths } from './api'

export { ConnectionConfig } from './connectionConfig'
export type { ConnectionOpts, Username } from './connectionConfig'
export {
AuthenticationError,
SandboxError,
TimeoutError,
NotFoundError,
NotEnoughSpaceError,
InvalidArgumentError,
NotEnoughSpaceError,
NotFoundError,
SandboxError,
TemplateError,
TimeoutError,
} from './errors'
export { ConnectionConfig } from './connectionConfig'
export type { Logger } from './logs'
export type { ConnectionOpts, Username } from './connectionConfig'

export { FilesystemEventType } from './sandbox/filesystem/watchHandle'
export type {
FilesystemEvent,
WatchHandle,
} from './sandbox/filesystem/watchHandle'
export type { EntryInfo, Filesystem, WatchOpts } from './sandbox/filesystem'
export { FileType } from './sandbox/filesystem'
export type { EntryInfo, Filesystem } from './sandbox/filesystem'
export { FilesystemEventType } from './sandbox/filesystem/watchHandle'
export type { FilesystemEvent, WatchHandle } from './sandbox/filesystem/watchHandle'

export { CommandExitError } from './sandbox/commands/commandHandle'
export type {
Expand All @@ -41,8 +38,8 @@ export type {
Pty,
} from './sandbox/commands'

export type { SandboxInfo } from './sandbox/sandboxApi'
export type { SandboxOpts } from './sandbox'
import { Sandbox } from './sandbox'
export type { SandboxInfo } from './sandbox/sandboxApi'
export { Sandbox }
import { Sandbox } from './sandbox'
export default Sandbox
Loading
Loading