Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Update docs

Vasek Mlejnskye624c7f1e730
diff --git a/apps/web/src/app/(docs)/docs/sandbox/connect/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/connect/page.mdx
new file mode 100644
index 000000000..63d54e0f0
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/sandbox/connect/page.mdx
@@ -0,0 +1,82 @@
+# Connect to running sandbox
+
+If you have a running sandbox, you can connect to it using the `Sandbox.connect()` method and then start controlling it with our SDK.
+
+This is useful if you want to, for example, reuse the same sandbox instance for the same user after a short period of inactivity.
+
+## 1. Get the sandbox ID
+To connect to a running sandbox, you first need to retrieve its ID. You can do this by calling the `Sandbox.list()` method.
+
+<CodeGroup>
+```js
+import { Sandbox } from "@e2b/code-interpreter"
+
+// Get all running sandboxes
+const runningSandboxes = await Sandbox.list() // $HighlightLine
+
+if (runningSandboxes.length === 0) {
+ throw new Error("No running sandboxes found")
+}
+
+// Get the ID of the sandbox you want to connect to
+const sandboxId = runningSandboxes[0].sandboxId
+```
+
+```python
+from e2b_code_interpreter import Sandbox
+
+# Get all running sandboxes
+running_sandboxes = Sandbox.list() # $HighlightLine
+
+# Get the ID of the sandbox you want to connect to
+if len(running_sandboxes) == 0:
+ raise Exception("No running sandboxes found")
+
+# Get the ID of the sandbox you want to connect to
+sandbox_id = running_sandboxes[0].sandbox_id
+```
+</CodeGroup>
+
+## 2. Connect to the sandbox
+
+Now that you have the sandbox ID, you can connect to the sandbox using the `Sandbox.connect()` method.
+
+<CodeGroup>
+```js
+import { Sandbox } from "@e2b/code-interpreter"
+
+// Get all running sandboxes
+const runningSandboxes = await Sandbox.list()
+
+if (runningSandboxes.length === 0) {
+ throw new Error("No running sandboxes found")
+}
+
+// Get the ID of the sandbox you want to connect to
+const sandboxId = runningSandboxes[0].sandboxId
+
+// Connect to the sandbox
+const sandbox = await Sandbox.connect(sandboxId) // $HighlightLine
+// Now you can use the sandbox as usual
+// ...
+
+```
+```python
+from e2b_code_interpreter import Sandbox
+
+# Get all running sandboxes
+running_sandboxes = Sandbox.list()
+
+# Get the ID of the sandbox you want to connect to
+if len(running_sandboxes) == 0:
+ raise Exception("No running sandboxes found")
+
+sandbox_id = running_sandboxes[0].sandbox_id
+
+# Connect to the sandbox
+sandbox = Sandbox.connect(sandbox_id) # $HighlightLine
+# Now you can use the sandbox as usual
+# ...
+
+```
+</CodeGroup>
diff --git a/apps/web/src/components/Navigation/routes.tsx b/apps/web/src/components/Navigation/routes.tsx
index 246bc060c..ff78c75e3 100644
--- a/apps/web/src/components/Navigation/routes.tsx
+++ b/apps/web/src/components/Navigation/routes.tsx
@@ -303,7 +303,7 @@ export const routes: NavGroup[] = [
href: '/docs/sandbox/list',
},
{
- title: '* Connect to running sandbox',
+ title: 'Connect to running sandbox',
href: '/docs/sandbox/connect',
},
{