Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
docs(python-sdk): document Agent Vault sessions and proxies
Scott Wilson6dda8b365d50
diff --git a/docs/documentation/platform/agent-vault/sessions.mdx b/docs/documentation/platform/agent-vault/sessions.mdxindex cf2d3070b7..fbca7230b4 100644--- a/docs/documentation/platform/agent-vault/sessions.mdx+++ b/docs/documentation/platform/agent-vault/sessions.mdx@@ -12,7 +12,7 @@ Every session is scoped to one access bundle and expires on a schedule you set.Anyone granted at least one access bundle can create a session. Admins can create one with any access bundle.<Tip>- If you want to create sessions programmatically, you can have a [machine identity](/documentation/platform/identities/machine-identities) create a new session for each run using [the CLI](/documentation/platform/agent-vault/sessions-cli) or [the API](/documentation/platform/agent-vault/sessions-api).+ If you want to create sessions programmatically, you can have a [machine identity](/documentation/platform/identities/machine-identities) create a new session for each run using [the CLI](/documentation/platform/agent-vault/sessions-cli), [the API](/documentation/platform/agent-vault/sessions-api), or [the Python SDK](/sdks/languages/python#agent_vault-sessions).</Tip><Tabs>diff --git a/docs/sdks/languages/python.mdx b/docs/sdks/languages/python.mdxindex d9f1178043..58591e520f 100644--- a/docs/sdks/languages/python.mdx+++ b/docs/sdks/languages/python.mdx@@ -75,6 +75,7 @@ The SDK methods are organized into the following high-level categories:3. `dynamic_secrets`: Manages dynamic secrets and leases.4. `kms`: Perform cryptographic operations with Infisical KMS.5. `folders`: Manages folder-related operations.+6. `agent_vault`: Manages Agent Vault sessions and proxies.### `auth`@@ -815,3 +816,245 @@ deleted_folder = client.folders.delete_folder(**Returns:**- `DeleteFolderResponseItem`: The response containing the deleted folder. Unlike the other folder responses, it doesn't include a `path` field.++### `agent_vault.sessions`++This sub-class manages [Agent Vault sessions](/documentation/platform/agent-vault/sessions). A session lets an AI agent use the services in one [access bundle](/documentation/platform/agent-vault/access-bundles) until the session expires or someone revokes it.++<Note>+ `agent_vault` requires `infisicalsdk` version 1.0.19 or newer.+</Note>++What the client can do with sessions depends on the [Agent Vault role](/documentation/platform/agent-vault/access-control#product-membership) of the user or machine identity that the client logs in as:++| Role | Can create sessions with | Can list, get, label, and revoke |+| --- | --- | --- |+| **Admin** | Any access bundle | Every session |+| **Member** | The access bundles [granted](/documentation/platform/agent-vault/access-bundles#grant-access) to the identity | The identity's own sessions |++#### List sessions++```python+from infisical_sdk import AgentVaultSessionScope, AgentVaultSessionStatus++sessions = client.agent_vault.sessions.list(+ scope=AgentVaultSessionScope.MINE, # Optional+ statuses=[AgentVaultSessionStatus.ACTIVE], # Optional+ search="nightly deploy", # Optional+ limit=20, # Optional+ offset=0 # Optional+)+```++**Parameters:**+- `scope` (Union[AgentVaultSessionScope, str], optional): whose sessions to list, either `AgentVaultSessionScope.MINE` for the identity's own sessions (the default) or `AgentVaultSessionScope.ALL` for every session (admins only)+- `statuses` (List[Union[AgentVaultSessionStatus, str]], optional): the statuses to include, from `ACTIVE`, `REVOKED`, and `EXPIRED` (defaults to all three)+- `search` (str, optional): text to find in each session's label, owner name, owner email, or access bundle name+- `limit` (int, optional): the maximum number of sessions to return, from 1 to 100 (defaults to `20`)+- `offset` (int, optional): the number of sessions to skip (defaults to `0`)++**Returns:**+- `ListAgentVaultSessionsResponse`: the sessions in `sessions`, and the total number of matching sessions in `totalCount`++#### Get session++```python+session = client.agent_vault.sessions.get(+ session_id="<session-id>"+)+```++**Parameters:**+- `session_id` (str): the ID of the session++**Returns:**+- `AgentVaultSession`: the session++#### Create session++```python+session = client.agent_vault.sessions.create(+ access_bundle="<access-bundle-name>",+ ttl="1h", # Optional+ label="nightly deploy" # Optional+)+```++**Parameters:**+- `access_bundle` (str): the name of the access bundle that the agent can use during the session+- `ttl` (str, optional): how long the session lasts, as a duration of at least one minute such as `30m`, `8h`, or `7d`, or as `never` for a session that doesn't expire (defaults to `7d`)+- `label` (str, optional): a short description of what the session is for, such as `nightly deploy` (up to 128 characters, without line breaks, tabs, or invisible characters)++**Returns:**+- `CreatedAgentVaultSession`: the new session, with the session token in `token` (Infisical returns the token only once)++Pass `session.token` to the agent as [Start the agent with the session token](/documentation/platform/agent-vault/sessions-api#step-4-start-the-agent-with-the-session-token) describes.++#### Update session label++Add, change, or remove a session's [label](/documentation/platform/agent-vault/sessions#label-a-session), for example to record what the agent is working on. You can also change the label after the session expires or is revoked.++```python+session = client.agent_vault.sessions.update(+ session_id="<session-id>",+ label="support ticket triage"+)+```++**Parameters:**+- `session_id` (str): the ID of the session+- `label` (Optional[str]): the new label (up to 128 characters, without line breaks, tabs, or invisible characters), or `None` to remove the label++**Returns:**+- `AgentVaultSession`: the updated session++#### Revoke session++Revoke a session when its agent finishes, even if the agent fails. The proxy stops attaching credentials for the session within one [poll interval](/documentation/platform/agent-vault/proxies#poll-interval).++```python+session = client.agent_vault.sessions.create(access_bundle="<access-bundle-name>")+try:+ run_agent(session.token) # Your code that starts the agent with the session token+finally:+ client.agent_vault.sessions.revoke(session_id=session.id)+```++**Parameters:**+- `session_id` (str): the ID of the session++**Returns:**+- `AgentVaultSession`: the revoked session++### `agent_vault.proxies`++This sub-class manages [Agent Vault proxies](/documentation/platform/agent-vault/proxies). A proxy attaches API credentials to the requests that agents send through it.++<Note>+ `agent_vault` requires `infisicalsdk` version 1.0.19 or newer.+</Note>++To use any method in this section except `list`, the client must log in as a user or machine identity with the **Admin** role in [Agent Vault](/documentation/platform/agent-vault/access-control#product-membership).++#### List proxies++```python+proxies = client.agent_vault.proxies.list(+ search="edge", # Optional+ order_by="name", # Optional+ order_direction="asc", # Optional+ limit=20, # Optional+ offset=0 # Optional+)+```++**Parameters:**+- `search` (str, optional): text to find in proxy names+- `order_by` (str, optional): what to sort the proxies by, `name` or `createdAt` (defaults to `createdAt`)+- `order_direction` (str, optional): the direction to sort in, `asc` or `desc` (defaults to `desc`)+- `limit` (int, optional): the maximum number of proxies to return, from 1 to 100 (defaults to `20`)+- `offset` (int, optional): the number of proxies to skip (defaults to `0`)++**Returns:**+- `ListAgentVaultProxiesResponse`: the proxies in `proxies`, and the total number of matching proxies in `totalCount`++If the client logs in as a member, each proxy's `trafficPolicy`, `allowedHosts`, `pollInterval`, and `createdAt` fields are `None`.++#### Create proxy++```python+from infisical_sdk import AgentVaultTrafficPolicy++response = client.agent_vault.proxies.create(+ name="edge-proxy",+ traffic_policy=AgentVaultTrafficPolicy.BUNDLE_HOSTS, # Optional+ allowed_hosts=["registry.npmjs.org", "pypi.org"], # Optional+ poll_interval=60 # Optional+)+```++**Parameters:**+- `name` (str): the name of the proxy, in lowercase letters, numbers, and hyphens (up to 64 characters)+- `traffic_policy` (Union[AgentVaultTrafficPolicy, str], optional): the proxy's [traffic policy](/documentation/platform/agent-vault/proxies#traffic-policy), either `ANY_HOST` to forward requests to any host (the default) or `BUNDLE_HOSTS` to refuse requests to hosts that no service in the session's access bundle covers+- `allowed_hosts` (Union[List[str], str], optional): hosts that agents can reach under `BUNDLE_HOSTS` even if no service covers them, as a list or a comma-separated string (see [Exceptions](/documentation/platform/agent-vault/proxies#exceptions))+- `poll_interval` (int, optional): how often, in seconds, the proxy checks its sessions and settings with Infisical, from 10 to 300 (defaults to `60`)++**Returns:**+- `AgentVaultProxyWithTokenResponse`: the proxy in `proxy`, and its proxy token in `proxyToken` (Infisical returns the token only once)++Start the proxy with the proxy token, as [Create a proxy and start it](/documentation/platform/agent-vault/proxies#create-a-proxy-and-start-it) shows.++#### Update proxy++Values you don't pass stay as they are. If the proxy is running, it applies the changes within one poll interval.++```python+proxy = client.agent_vault.proxies.update(+ proxy_id="<proxy-id>",+ name="edge-proxy", # Optional+ traffic_policy=AgentVaultTrafficPolicy.BUNDLE_HOSTS, # Optional+ allowed_hosts=["pypi.org"], # Optional+ poll_interval=30 # Optional+)+```++**Parameters:**+- `proxy_id` (str): the ID of the proxy+- `name` (str, optional): the new name of the proxy+- `traffic_policy` (Union[AgentVaultTrafficPolicy, str], optional): the new traffic policy+- `allowed_hosts` (Union[List[str], str], optional): the new exceptions, which replace the current ones+- `poll_interval` (int, optional): the new poll interval in seconds, from 10 to 300+- `clear_allowed_hosts` (bool, optional): set to `True` to remove every exception (raises a `ValueError` if you also pass `allowed_hosts`)++**Returns:**+- `AgentVaultProxy`: the updated proxy++#### Delete proxy++```python+proxy = client.agent_vault.proxies.delete(+ proxy_id="<proxy-id>"+)+```++**Parameters:**+- `proxy_id` (str): the ID of the proxy++<Warning>+ You can't undo deleting a proxy. To stop a proxy temporarily, [revoke its access](#revoke-proxy) instead.+</Warning>++**Returns:**+- `AgentVaultProxy`: the deleted proxy, with only `id` and `name` set++#### Rotate proxy token++Issue a new proxy token if the current one leaked, or to bring back a proxy whose access you revoked. The old token stops working right away. To restart the proxy and its agents, follow the steps in [Rotate a proxy's token](/documentation/platform/agent-vault/proxies#rotate-a-proxy’s-token).++```python+response = client.agent_vault.proxies.rotate_token(+ proxy_id="<proxy-id>"+)+```++**Parameters:**+- `proxy_id` (str): the ID of the proxy++**Returns:**+- `AgentVaultProxyWithTokenResponse`: the proxy in `proxy`, and the new proxy token in `proxyToken` (Infisical returns the token only once)++#### Revoke proxy++Revoke a proxy's access if you think a machine that runs the proxy is compromised. The proxy stops attaching credentials to requests until you [rotate its token](#rotate-proxy-token).++```python+proxy = client.agent_vault.proxies.revoke(+ proxy_id="<proxy-id>"+)+```++**Parameters:**+- `proxy_id` (str): the ID of the proxy++**Returns:**+- `AgentVaultProxy`: the revoked proxy