mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Disable code sandbox if no code sandbox configured by admin
Either set the Terrarium sandbox url or the E2B api key to enable code sandbox
This commit is contained in:
@@ -39,7 +39,7 @@ from khoj.utils.rawconfig import LocationData
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
SANDBOX_URL = os.getenv("KHOJ_TERRARIUM_URL", "http://localhost:8080")
|
SANDBOX_URL = os.getenv("KHOJ_TERRARIUM_URL")
|
||||||
DEFAULT_E2B_TEMPLATE = "pmt2o0ghpang8gbiys57"
|
DEFAULT_E2B_TEMPLATE = "pmt2o0ghpang8gbiys57"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ from khoj.utils.helpers import (
|
|||||||
ToolDefinition,
|
ToolDefinition,
|
||||||
get_file_type,
|
get_file_type,
|
||||||
in_debug_mode,
|
in_debug_mode,
|
||||||
|
is_code_sandbox_enabled,
|
||||||
is_none_or_empty,
|
is_none_or_empty,
|
||||||
is_operator_enabled,
|
is_operator_enabled,
|
||||||
is_valid_url,
|
is_valid_url,
|
||||||
@@ -370,6 +371,8 @@ async def aget_data_sources_and_output_format(
|
|||||||
continue
|
continue
|
||||||
if source in [ConversationCommand.Online, ConversationCommand.Webpage] and not is_web_search_enabled():
|
if source in [ConversationCommand.Online, ConversationCommand.Webpage] and not is_web_search_enabled():
|
||||||
continue
|
continue
|
||||||
|
if source == ConversationCommand.Code and not is_code_sandbox_enabled():
|
||||||
|
continue
|
||||||
source_options[source.value] = description
|
source_options[source.value] = description
|
||||||
if len(agent_sources) == 0 or source.value in agent_sources:
|
if len(agent_sources) == 0 or source.value in agent_sources:
|
||||||
source_options_str += f'- "{source.value}": "{description}"\n'
|
source_options_str += f'- "{source.value}": "{description}"\n'
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ from khoj.utils.helpers import (
|
|||||||
ConversationCommand,
|
ConversationCommand,
|
||||||
ToolDefinition,
|
ToolDefinition,
|
||||||
dict_to_tuple,
|
dict_to_tuple,
|
||||||
|
is_code_sandbox_enabled,
|
||||||
is_none_or_empty,
|
is_none_or_empty,
|
||||||
is_operator_enabled,
|
is_operator_enabled,
|
||||||
is_web_search_enabled,
|
is_web_search_enabled,
|
||||||
@@ -120,6 +121,10 @@ async def apick_next_tool(
|
|||||||
# Skip showing web search tool if agent has no access to internet
|
# Skip showing web search tool if agent has no access to internet
|
||||||
if tool in web_research_tools and not is_web_search_enabled():
|
if tool in web_research_tools and not is_web_search_enabled():
|
||||||
continue
|
continue
|
||||||
|
# Skip showing code tool if agent has no access to code execution sandbox
|
||||||
|
if tool == ConversationCommand.PythonCoder and not is_code_sandbox_enabled():
|
||||||
|
continue
|
||||||
|
# Format description with relevant usage limits
|
||||||
if tool == ConversationCommand.SemanticSearchFiles:
|
if tool == ConversationCommand.SemanticSearchFiles:
|
||||||
description = tool_data.description.format(max_search_queries=max_document_searches)
|
description = tool_data.description.format(max_search_queries=max_document_searches)
|
||||||
elif tool == ConversationCommand.ReadWebpage:
|
elif tool == ConversationCommand.ReadWebpage:
|
||||||
|
|||||||
@@ -777,6 +777,12 @@ def is_operator_enabled():
|
|||||||
return is_env_var_true("KHOJ_OPERATOR_ENABLED")
|
return is_env_var_true("KHOJ_OPERATOR_ENABLED")
|
||||||
|
|
||||||
|
|
||||||
|
def is_code_sandbox_enabled():
|
||||||
|
"""Check if Khoj can run code in sandbox.
|
||||||
|
Set KHOJ_TERRARIUM_URL or E2B api key via env var to enable it."""
|
||||||
|
return not is_none_or_empty(os.getenv("KHOJ_TERRARIUM_URL")) or is_e2b_code_sandbox_enabled()
|
||||||
|
|
||||||
|
|
||||||
def is_valid_url(url: str) -> bool:
|
def is_valid_url(url: str) -> bool:
|
||||||
"""Check if a string is a valid URL"""
|
"""Check if a string is a valid URL"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user