Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Improve API key is missing error message (#293)

Jakub Novák239f3fcf3299
diff --git a/packages/js-sdk/src/sandbox/sandboxConnection.ts b/packages/js-sdk/src/sandbox/sandboxConnection.ts
index 5433fdad1..cd4de3052 100644
--- a/packages/js-sdk/src/sandbox/sandboxConnection.ts
+++ b/packages/js-sdk/src/sandbox/sandboxConnection.ts
@@ -96,7 +96,9 @@ export class SandboxConnection {
const apiKey = opts.apiKey || process?.env?.E2B_API_KEY
if (!apiKey) {
throw new AuthenticationError(
- 'API key is required, please visit https://e2b.dev/docs to get your API key',
+ 'API key is required, please visit https://e2b.dev/docs to get your API key. ' +
+ 'You can either set the environment variable `E2B_API_KEY` ' +
+ "or you can pass it directly to the sandbox like Sandbox.create({apiKey: 'e2b_...'})",
)
}
this.apiKey = apiKey
diff --git a/packages/python-sdk/e2b/sandbox/process.py b/packages/python-sdk/e2b/sandbox/process.py
index a5d4e9732..ab63bf2f0 100644
--- a/packages/python-sdk/e2b/sandbox/process.py
+++ b/packages/python-sdk/e2b/sandbox/process.py
@@ -339,7 +339,9 @@ class ProcessManager:
logger.exception(f"Error in on_exit callback: {error}")
future_exit_handler_finish.set_result(output)
- threading.Thread(name="e2b-process-exit-handler", daemon=True, target=exit_handler).start()
+ threading.Thread(
+ name="e2b-process-exit-handler", daemon=True, target=exit_handler
+ ).start()
def trigger_exit():
logger.info(f"Exiting the process (id: {process_id})")
diff --git a/packages/python-sdk/e2b/sandbox/sandbox_connection.py b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
index 71f11c98c..71b2c71e3 100644
--- a/packages/python-sdk/e2b/sandbox/sandbox_connection.py
+++ b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
@@ -25,7 +25,8 @@ from e2b.sandbox.exception import (
AuthenticationException,
MultipleExceptions,
SandboxException,
- TimeoutException, SandboxNotOpenException,
+ TimeoutException,
+ SandboxNotOpenException,
)
from e2b.sandbox.sandbox_rpc import Notification, SandboxRpc
from e2b.utils.future import DeferredFuture
@@ -93,7 +94,9 @@ class SandboxConnection:
if api_key is None:
raise AuthenticationException(
- "API key is required, please visit https://e2b.dev/docs to get your API key",
+ "API key is required, please visit https://e2b.dev/docs to get your API key. "
+ "You can either set the environment variable `E2B_API_KEY` "
+ 'or you can pass it directly to the sandbox like Sandbox(api_key="e2b_...")',
)
self.cwd = cwd
diff --git a/packages/python-sdk/e2b/sandbox/terminal.py b/packages/python-sdk/e2b/sandbox/terminal.py
index 36c08edce..c2af52bd8 100644
--- a/packages/python-sdk/e2b/sandbox/terminal.py
+++ b/packages/python-sdk/e2b/sandbox/terminal.py
@@ -204,7 +204,7 @@ class TerminalManager:
) from e
# TODO: Handle exit handler finish for exits (the same for processes)
- future_exit_handler_finish = Future[TerminalOutput]( )
+ future_exit_handler_finish = Future[TerminalOutput]()
def exit_handler():
future_exit.result()
@@ -216,7 +216,9 @@ class TerminalManager:
on_exit()
future_exit_handler_finish.set_result(output)
- threading.Thread(name="e2b-terminal-exit-handler", daemon=True, target=exit_handler).start()
+ threading.Thread(
+ name="e2b-terminal-exit-handler", daemon=True, target=exit_handler
+ ).start()
def trigger_exit():
future_exit.set_result(None)