Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/orange-hotels-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2b/cli': patch
---

Returns a url to inspect a spawned sandbox inside the dashboard.
3 changes: 3 additions & 0 deletions packages/cli/src/commands/sandbox/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,6 +92,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)
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
23 changes: 23 additions & 0 deletions packages/cli/src/utils/urls.ts
Original file line number Diff line number Diff line change
@@ -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('')
}