Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Rework API keys in docs

Jakub Novakf70059dcda53
diff --git a/apps/docs/src/app/getting-started/api-key/APIKey.tsx b/apps/docs/src/app/getting-started/api-key/APIKey.tsx
index 0bffea78c..883032cbd 100644
--- a/apps/docs/src/app/getting-started/api-key/APIKey.tsx
+++ b/apps/docs/src/app/getting-started/api-key/APIKey.tsx
@@ -1,55 +1,124 @@
-'use client'
+"use client";
-import clsx from 'clsx'
-import { Button } from '@/components/Button'
-import { useApiKey, useUser } from '@/utils/useUser'
-import { obfuscateSecret } from '@/utils/obfuscate'
-import { CopyButton } from '@/components/CopyButton'
-import { usePostHog } from 'posthog-js/react'
-import { useSignIn } from '@/utils/useSignIn'
+import clsx from "clsx";
+import { useAccessToken, useApiKey, useUser } from "@/utils/useUser";
+import { usePostHog } from "posthog-js/react";
+import { useSignIn } from "@/utils/useSignIn";
+import { obfuscateSecret } from "@/utils/obfuscate";
+import { Button } from "@/components/Button";
+import { CopyButton } from "@/components/CopyButton";
+import { Note } from '@/components/mdx'
+export function CopyableSecret({
+ secret,
+ onAfterCopy,
+ obfuscateStart,
+ obfuscateEnd,
+}: {
+ secret: string;
+ onAfterCopy: () => void;
+ obfuscateStart?: number;
+ obfuscateEnd?: number;
+}) {
+ return (
+ <div className="relative flex">
+ <span className="whitespace-nowrap font-mono text-yellow-400 group-hover:opacity-0">
+ {obfuscateSecret(secret, obfuscateStart, obfuscateEnd)}
+ </span>
+ <span className="absolute inset-0">
+ <CopyButton
+ code={secret}
+ onAfterCopy={onAfterCopy}
+ customPositionClassNames={clsx(
+ "top-[-2px] bottom-[2px]" /* nudge 2px up*/,
+ "left-[-8px] right-[-8px]" /* widen a little to fit nicely */,
+ "min-h-[28px]"
+ )}
+ />
+ </span>
+ </div>
+ );
+}
+
+function SecretBlock({ name, description, secret, posthog, tip }) {
+ return (
+ <div className="flex flex-col space-y-1">
+ <h2 className="flex flex-row items-center justify-items-end align-text-bottom mt-6">
+ <span>{name}</span>
+ <div className="group text-sm ml-4 border-2 mt-1 outline-2 outline-offset-2 outline-zinc-700 rounded-full px-[8px]">
+ <CopyableSecret
+ secret={secret}
+ onAfterCopy={() => posthog?.capture("copied API key")}
+ obfuscateStart={12}
+ obfuscateEnd={5}
+ />
+ </div>
+ </h2>
+ <span>{description}</span>
+ <span>{tip}</span>
+ </div>
+ );
+}
function APIKey() {
- const signIn = useSignIn()
- const { user } = useUser()
- const apiKey = useApiKey()
- const posthog = usePostHog()
+ const signIn = useSignIn();
+ const { user } = useUser();
+ const apiKey = useApiKey();
+ const posthog = usePostHog();
+ const accessToken = useAccessToken();
return (
- <div className="flex flex-col items-start justify-start space-y-4">
+ <div className="flex flex-col items-start justify-start -mb-6">
{user ? (
- <div
- className="
- group relative flex
- flex-row
- gap-2 text-xs
- "
- >
- <span className="whitespace-nowrap font-bold text-zinc-400 group-hover:opacity-25">
- API Key
- </span>
- <span className="whitespace-nowrap font-mono text-yellow-400 group-hover:opacity-25">
- {obfuscateSecret(apiKey)}
- </span>
- <span className="absolute inset-0">
- <CopyButton
- code={apiKey}
- onAfterCopy={() => posthog?.capture('copied API key')}
- customPositionClassNames={clsx(
- 'top-[-2px] bottom-[2px]' /* nudge 2px up*/,
- 'left-[-6px] right-[-6px]' /* widen a little to fit nicely */,
- 'min-h-[28px]',
- )}
- />
- </span>
+ <div className="flex flex-col space-y-4">
+ <SecretBlock
+ name="API Key"
+ description={
+ <span>
+ Use for <strong>running</strong> the sandboxes.
+ </span>
+ }
+ secret={apiKey}
+ posthog={posthog}
+ tip={
+ <span>
+ Set as <code>E2B_API_KEY</code> environment variable to avoid passing it
+ every time.
+ </span>
+ }
+ />
+ <SecretBlock
+ name="Access Token"
+ description={
+ <div className="flex flex-col">
+ <span>
+ Use for <strong>managing</strong> the sandboxes
+ (creating/listing/deleting).
+ </span>
+ <span>
+ Not needed when logging in CLI via <code>e2b login</code>.
+ </span>
+ </div>
+ }
+ secret={accessToken}
+ posthog={posthog}
+ tip={
+ <Note>
+ <div className="flex flex-col">
+ <span>To authenticate without the browser, you can set <code>E2B_ACCESS_TOKEN</code> as an environment variable.</span>
+ <span>This can be useful for CI/CD pipelines.</span>
+ </div>
+ </Note>
+ }
+ />
</div>
) : (
- <>
+ <div className="mt-6">
<span>You can get your API key by signing up.</span>
<Button onClick={() => signIn()}>Sign up to get your API key</Button>
- </>
+ </div>
)}
</div>
- )
+ );
}
-export default APIKey
+export default APIKey;
diff --git a/apps/docs/src/components/Auth.tsx b/apps/docs/src/components/Auth.tsx
index ee169227e..955efce2f 100644
--- a/apps/docs/src/components/Auth.tsx
+++ b/apps/docs/src/components/Auth.tsx
@@ -1,7 +1,7 @@
import { Button } from '@/components/Button'
import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'
import { useRouter } from 'next/navigation'
-import { useAccessToken, useApiKey, useUser } from '@/utils/useUser'
+import { useApiKey, useUser } from '@/utils/useUser'
import { LogOutIcon } from 'lucide-react'
import { CopyButton } from '@/components/CopyButton'
import clsx from 'clsx'
@@ -10,7 +10,6 @@ import { usePostHog } from 'posthog-js/react'
import { obfuscateSecret } from '@/utils/obfuscate'
import { useSignIn } from '@/utils/useSignIn'
-import { Popover, PopoverContent, PopoverTrigger } from './ui/Popover'
function CopyableSecret({
secret = '',
@@ -47,7 +46,6 @@ export const Auth = function () {
const { user, isLoading, error } = useUser()
const signIn = useSignIn()
const apiKey = useApiKey()
- const accessToken = useAccessToken()
const posthog = usePostHog()
const router = useRouter()
const supabase = createClientComponentClient()
@@ -98,62 +96,9 @@ export const Auth = function () {
</div>
<HeaderSeparator/>
<div className="flex items-center gap-2">
- <Popover>
- <PopoverTrigger
- className="
- whitespace-nowrap text-xs font-bold
- "
- >
- {user.email}
- </PopoverTrigger>
- <PopoverContent className="w-144">
- <div className="flex flex-col gap-4">
- <div className="flex flex-col">
- <span className="text-xs font-bold">API Key</span>
- <span className="text-xs text-gray-200">
- Use for <strong>running</strong> the sandboxes.
- </span>
- <div className="group relative text-xs">
- <CopyableSecret
- secret={apiKey}
- onAfterCopy={() => posthog?.capture('copied API key')}
- obfuscateStart={12}
- obfuscateEnd={5}
- />
- </div>
- <span className="text-xs text-gray-400">
- TIP: Set as <code>E2B_API_KEY</code> env var to avoid
- passing it every time.
- </span>
- </div>
- <div className="flex flex-col">
- <span className="text-xs font-bold">Access Token</span>
- <span className="text-xs text-gray-200">
- Use for <strong>managing</strong> the sandboxes
- (creating/listing/deleting).
- </span>
- <span className="text-xs text-gray-200">
- Not needed when logging in via CLI via{' '}
- <code>e2b login</code>
- </span>
- <div className="group relative text-xs">
- <CopyableSecret
- secret={accessToken}
- onAfterCopy={() =>
- posthog?.capture('copied Access Token')
- }
- obfuscateStart={12}
- obfuscateEnd={5}
- />
- </div>
- <span className="text-xs text-gray-400">
- TIP: Set as <code>E2B_ACCESS_TOKEN</code> env var to avoid
- passing it every time.
- </span>
- </div>
- </div>
- </PopoverContent>
- </Popover>
+ <div className="whitespace-nowrap text-xs font-bold">
+ {user.email}
+ </div>
{/* @ts-ignore */}
<Button
variant="textSubtle"
diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts
index 4565fed4e..b3783c31e 100644
--- a/packages/cli/src/index.ts
+++ b/packages/cli/src/index.ts
@@ -18,7 +18,7 @@ updateNotifier.default({
program
.version(packageJSON.version, undefined, 'Display E2B CLI version')
.addOption(new Option('-cmd2json').hideHelp()).on('option:-cmd2json', () => {
- process.stdout.write(JSON.stringify((program.commands.sort((row1: any, row2: any) => row1.name().localeCompare(row2.name())).map((x: any) => ({
+ process.stdout.write(JSON.stringify((program.commands.map((x: any) => ({
command: x.name(),
description: stripAnsi.default(x.description()),
options: x.options.map((y: any) => ({
@@ -26,6 +26,6 @@ program
description: stripAnsi.default(y.description),
defaultValue: y.defaultValue,
})),
- })))));
- process.exit();
+ })).sort((row1: any, row2: any) => row1.name().localeCompare(row2.name())))));
+ process.exit(0);
}).parse();