Skip to content

Commit 4540c86

Browse files
authored
Merge branch 'main' into return-error-indicating-that-the-sandbox-is-not-running-when-e2b-1327-test
2 parents f5cde50 + dde83b7 commit 4540c86

File tree

39 files changed

+4028
-114
lines changed

39 files changed

+4028
-114
lines changed

apps/web/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"autoprefixer": "^10.4.7",
4444
"class-variance-authority": "^0.7.0",
4545
"clsx": "^1.2.1",
46-
"e2b": "^1.0.5",
46+
"e2b": "^1.0.6",
4747
"fast-glob": "^3.3.0",
4848
"fast-xml-parser": "^4.3.3",
4949
"flexsearch": "^0.7.31",

apps/web/src/app/(docs)/docs/filesystem/watch/page.mdx

+49
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,52 @@ for event in events: # $HighlightLine
3939
print(f"wrote to file {event.name}") # $HighlightLine
4040
```
4141
</CodeGroup>
42+
43+
44+
## Recursive Watching
45+
46+
You can enable recursive watching using the parameter `recursive`.
47+
48+
<Note>
49+
When rapidly creating new folders (e.g., deeply nested path of folders), events other than `CREATE` might not be emitted. To avoid this behavior, create the required folder structure in advance.
50+
</Note>
51+
52+
<CodeGroup>
53+
```js
54+
import { Sandbox, FilesystemEventType } from '@e2b/code-interpreter'
55+
56+
const sandbox = await Sandbox.create()
57+
const dirname = '/home/user'
58+
59+
// Start watching directory for changes
60+
const handle = await sandbox.files.watchDir(dirname, async (event) => {
61+
console.log(event)
62+
if (event.type === FilesystemEventType.WRITE) {
63+
console.log(`wrote to file ${event.name}`)
64+
}
65+
}, {
66+
recursive: true // $HighlightLine
67+
})
68+
69+
// Trigger file write event
70+
await sandbox.files.write(`${dirname}/my-folder/my-file`, 'hello') // $HighlightLine
71+
```
72+
```python
73+
from e2b_code_interpreter import Sandbox
74+
75+
sandbox = Sandbox()
76+
dirname = '/home/user'
77+
78+
# Watch directory for changes
79+
handle = sandbox.files.watch_dir(dirname, recursive=True) # $HighlightLine
80+
# Trigger file write event
81+
sandbox.files.write(f"{dirname}/my-folder/my-file", "hello") # $HighlightLine
82+
83+
# Retrieve the latest new events since the last `get_new_events()` call
84+
events = handle.get_new_events()
85+
for event in events:
86+
print(event)
87+
if event.type == FilesystemEventType.Write:
88+
print(f"wrote to file {event.name}")
89+
```
90+
</CodeGroup>

0 commit comments

Comments
 (0)