Code Tools: access to internal resources

Code Tool code never connects to any other internal system directly. It is a Python handler(params, context) that runs in an isolated sandbox. The platform gives it two things at run time: getAuthHeader(alias) for auth, and context for everything else. Internal data is reached only through Leena's own HTTP APIs, the same way the code calls Workday or ServiceNow.

How a run gets its auth

The code gets a helper, never a stored credential.

  1. Tool is bound to a connection. When the tool is saved, each alias (e.g. workday, leena) points to a Leena AI Integrations connection.
  2. AI Colleague calls the tool. The AOP tool call sends params, bot_id and the user to the code-exec gateway.
  3. Gateway resolves auth. It gets each bound connection's auth from Leena AI Integrations. This region's Leena hosts travel with the run.
  4. Sandbox injects the helpers. getAuthHeader(alias) and context (bot_id, user_profile, Leena hosts) are added before the code runs.
  5. Code calls the API. requests with those headers. Tokens are redacted from output and logs; the return value goes back.

Credentials stay in Leena AI Integrations until the gateway resolves them for one run; the code only ever calls the injected helper.

What getAuthHeader is

getAuthHeader(alias) is a helper function the sandbox adds to Python's built-ins, so the code calls it without importing or defining it. It returns the auth for the Integration connection bound to that alias.

Connection auth typeReturnsWhat the code does
Bearer, basic{"authorization": "Bearer …"}Passes it straight to requests as headers
Raw{"authorization": "<token>"}Adds the scheme prefix if the API needs one
API key{"apiKey": "…"}Puts it in the header or query parameter the API expects
None{}Nothing
def handler(params, context):
    auth = getAuthHeader("workday")
    r = requests.get(url, headers=auth)
  • No stored secrets. No key or token is written in the code or stored in Leena's database.
  • Hidden from output, not from the code. The token is inside the sandbox. The guarantee is that it is removed from all output, logs and error traces, so it never leaves the run.
  • Second helper. context.call_connection(alias, method, path) makes the authenticated call itself.

Reaching Leena's own resources

Internal resources are reached through context and the bot's leena-x-app-secret connection. Hosts and bot IDs are never hardcoded, because they differ by region and customer.

Code Tools are not given MongoDB IDs directly. They do get the bot ID and the user's details as context, listed below.

NeedWhere the code gets it
Auth to Leena's APIsgetAuthHeader("leena"), with the leena-x-app-secret connection (under the REST API connection) bound as alias leena
Which customermost Leena paths are /bots/{bot_id}/…
Who the tool acts foruser_profile (employee_id, email, display_name)
Any other ID the tool needsPassed in as a tool parameter, filled by the AI Colleague when it calls the tool
Base URL, tenant ID and similarThe connection's config fields
Any other settingAn env store key

Leena AI connector actions

Code Tools can use whatever the pre-built Leena AI connector exposes. The code calls the same Leena APIs as the connector's actions:

AreaActions
NotificationsSend notification on virtual assistant; send email notification
TicketsRaise ticket in Leena AI’s own native Case Management/Helpdesk
EmployeesFetch an employee's details; get employees with filters
Master tablesFetch master table; upsert master table records (Master Tables are maintained within Workflows Studio)
VerificationGenerate, regenerate and validate OTP; sign JWT token
LettersGenerate letter
FilesConvert a file to PDF; combine PDF, PNG and JPG files into one PDF; Excel or CSV to JSON; JSON to Excel; parse EML file; QR code from a string; attachment hash (SHA-256); URL to Base64 and back
WorkflowsGet workflow item IDs; withdraw workflow items

Did this page help you?