Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Feat: Print sandbox inspect url on sandbox spawn (#841)

Ben Fornefelda26e2136f691
diff --git a/.changeset/slimy-shrimps-attend.md b/.changeset/slimy-shrimps-attend.md
new file mode 100644
index 000000000..2c60b774a
--- /dev/null
+++ b/.changeset/slimy-shrimps-attend.md
@@ -0,0 +1,5 @@
+---
+'@e2b/cli': patch
+---
+
+Print Sandbox Inspect url for E2B Dashboard Inspection
diff --git a/packages/cli/src/commands/sandbox/connect.ts b/packages/cli/src/commands/sandbox/connect.ts
index d39b4a811..1f6ba0b5b 100644
--- a/packages/cli/src/commands/sandbox/connect.ts
+++ b/packages/cli/src/commands/sandbox/connect.ts
@@ -4,6 +4,7 @@ import * as commander from 'commander'
import { spawnConnectedTerminal } from 'src/terminal'
import { asBold, asPrimary } from 'src/utils/format'
import { ensureAPIKey } from '../../api'
+import { printDashboardSandboxInspectUrl } from 'src/utils/urls'
export const connectCommand = new commander.Command('connect')
.description('connect terminal to already running sandbox')
@@ -37,6 +38,8 @@ async function connectToSandbox({
}) {
const sandbox = await e2b.Sandbox.connect(sandboxID, { apiKey })
+ printDashboardSandboxInspectUrl(sandbox.sandboxId)
+
console.log(
`Terminal connecting to sandbox ${asPrimary(`${sandbox.sandboxId}`)}`
)
diff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.ts
index 16e159d35..7c29aadfa 100644
--- a/packages/cli/src/commands/sandbox/create.ts
+++ b/packages/cli/src/commands/sandbox/create.ts
@@ -9,6 +9,7 @@ import { getRoot } from '../../utils/filesystem'
import { getConfigPath, loadConfig } from '../../config'
import fs from 'fs'
import { configOption, pathOption } from '../../options'
+import { printDashboardSandboxInspectUrl } from 'src/utils/urls'
export function createCommand(
name: string,
@@ -88,6 +89,8 @@ export async function connectSandbox({
}) {
const sandbox = await e2b.Sandbox.create(template.templateID, { apiKey })
+ printDashboardSandboxInspectUrl(sandbox.sandboxId)
+
// keep-alive loop
const intervalId = setInterval(async () => {
await sandbox.setTimeout(30_000)
diff --git a/packages/cli/src/user.ts b/packages/cli/src/user.ts
index 3e1b3129a..be1e86d8c 100644
--- a/packages/cli/src/user.ts
+++ b/packages/cli/src/user.ts
@@ -15,10 +15,18 @@ export interface UserConfig {
}
export const USER_CONFIG_PATH = path.join(os.homedir(), '.e2b', 'config.json') // TODO: Keep in Keychain
+
export const DOCS_BASE =
process.env.E2B_DOCS_BASE ||
`https://${process.env.E2B_DOMAIN || 'e2b.dev'}/docs`
+export const DASHBOARD_BASE =
+ process.env.E2B_DASHBOARD_BASE ||
+ `https://${process.env.E2B_DOMAIN || 'e2b.dev'}/dashboard`
+
+export const SANDBOX_INSPECT_URL = (sandboxId: string) =>
+ `${DASHBOARD_BASE}/inspect/sandbox/${sandboxId}`
+
export function getUserConfig(): UserConfig | null {
if (!fs.existsSync(USER_CONFIG_PATH)) return null
return JSON.parse(fs.readFileSync(USER_CONFIG_PATH, 'utf8'))
diff --git a/packages/cli/src/utils/urls.ts b/packages/cli/src/utils/urls.ts
new file mode 100644
index 000000000..083099fdb
--- /dev/null
+++ b/packages/cli/src/utils/urls.ts
@@ -0,0 +1,23 @@
+import { SANDBOX_INSPECT_URL } from 'src/user'
+import { asPrimary } from './format'
+
+/**
+ * Prints a clickable URL to the E2B Dashboard for inspecting a sandbox
+ *
+ * This function creates a terminal-clickable link that allows users to
+ * inspect their sandbox in the E2B Dashboard. The link is formatted with
+ * ANSI escape sequences to make it clickable in compatible terminals.
+ *
+ * @param {string} sandboxId - The ID of the sandbox to inspect
+ */
+export const printDashboardSandboxInspectUrl = (sandboxId: string) => {
+ const url = SANDBOX_INSPECT_URL(sandboxId)
+ const clickable = `\u001b]8;;${url}\u0007${url}\u001b]8;;\u0007`
+
+ console.log('')
+ console.log(
+ 'Use the following link to inspect this Sandbox live inside the E2B Dashboard️:'
+ )
+ console.log(asPrimary(`↪ ${clickable}`))
+ console.log('')
+}