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.
- Tool is bound to a connection. When the tool is saved, each alias (e.g. workday, leena) points to a Leena AI Integrations connection.
- AI Colleague calls the tool. The AOP tool call sends params,
bot_idand the user to the code-exec gateway. - Gateway resolves auth. It gets each bound connection's auth from Leena AI Integrations. This region's Leena hosts travel with the run.
- Sandbox injects the helpers.
getAuthHeader(alias)andcontext(bot_id,user_profile, Leena hosts) are added before the code runs. - Code calls the API.
requestswith 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 type | Returns | What 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.
| Need | Where the code gets it |
|---|---|
| Auth to Leena's APIs | getAuthHeader("leena"), with the leena-x-app-secret connection (under the REST API connection) bound as alias leena |
| Which customer | most Leena paths are /bots/{bot_id}/… |
| Who the tool acts for | user_profile (employee_id, email, display_name) |
| Any other ID the tool needs | Passed in as a tool parameter, filled by the AI Colleague when it calls the tool |
| Base URL, tenant ID and similar | The connection's config fields |
| Any other setting | An 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:
| Area | Actions |
|---|---|
| Notifications | Send notification on virtual assistant; send email notification |
| Tickets | Raise ticket in Leena AI’s own native Case Management/Helpdesk |
| Employees | Fetch an employee's details; get employees with filters |
| Master tables | Fetch master table; upsert master table records (Master Tables are maintained within Workflows Studio) |
| Verification | Generate, regenerate and validate OTP; sign JWT token |
| Letters | Generate letter |
| Files | Convert 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 |
| Workflows | Get workflow item IDs; withdraw workflow items |
Updated 1 day ago
