diff --git a/.changeset/orange-hotels-worry.md b/.changeset/orange-hotels-worry.md new file mode 100644 index 0000000000..7be734515d --- /dev/null +++ b/.changeset/orange-hotels-worry.md @@ -0,0 +1,5 @@ +--- +'@e2b/cli': patch +--- + +Returns a url to inspect a spawned sandbox inside the dashboard. diff --git a/packages/cli/src/commands/sandbox/create.ts b/packages/cli/src/commands/sandbox/create.ts index 3bde937832..51c00b47c7 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, @@ -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) diff --git a/packages/cli/src/user.ts b/packages/cli/src/user.ts index 3e1b3129a9..be1e86d8c0 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 0000000000..083099fdbc --- /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('') +}