# Agent session grants (/docs/swivy/agent-session-grants)

<Callout type="warn" title="Preview: Swivy is not generally available">
Swivy is a **staging/testnet preview using software custody**, not a production custody service. All six public SDK packages are available at **1.0.1**. Use test assets only. [Set up the preview](/docs/swivy/preview-setup) or [request project access](/docs/swivy/request-access).
</Callout>

An AI agent that trades or pays for a user needs to sign. Giving it the wallet's key would be dangerous. A **session grant** gives it a narrow, expiring permission instead:

- tied to **one user and one wallet**;
- limited to the **signing kinds** you allow (for example messages and transactions);
- limited to the **networks** you allow;
- optionally capped at a **maximum transaction value** in USD;
- **time-bounded and use-limited**, and revocable.

The agent gets its own key pair. Swivy checks every request it signs against the grant, so a leaked agent key can only do what the grant allows, until the grant expires.

This is the same job delegated signing does for Ovi and the Swop MCP today.

## Issue a grant [#issue-a-grant]

The user approves the grant with their passkey first; pass that `challengeId`.

```ts
import { SwivyNodeClient, generateSessionKeyPair } from '@swivy/node';

const sessionKeys = generateSessionKeyPair(); // the agent's own key pair

const grant = await swivy.createSessionGrant({
  accountId: 'acct_...',
  publicKey: sessionKeys.publicKeyPem,
  challengeId: 'challenge_...',
  scope: {
    allowedNetworks: ['base-sepolia'],
    allowTransactionExecution: true,
    allowedSigningKinds: ['sign_message', 'sign_typed_data', 'sign_transaction'],
    maxTransactionValueUsd: 500,
  },
});
```

## Act with the grant [#act-with-the-grant]

```ts
const intent = await swivy.createTransactionIntentWithSessionGrant(
  grant.sessionGrant,
  sessionKeys.privateKeyPem, // the agent's key, never the wallet's
  {
    network: 'base-sepolia',
    transaction: { to: '0x1111111111111111111111111111111111111111', value: '0x0', data: '0x' },
  },
);
```

## Standing grants and rules [#standing-grants-and-rules]

Available in the testnet preview when permitted by environment policy. Standing EVM grants require an explicit `rules.evm.maxExecutionGasCostWei` limit; SDK types alone do not enforce that requirement. See [delegated execution limits](/docs/swivy/delegated-limits).

- **Standing grants** (`scope.standing: true`) stay valid until the user revokes them, like a Privy signer. Your environment has to allow them, and each one must carry rules.
- **Rules** (`scope.rules`) are checked against what each intent actually does. Anything they don't allow is refused.

| Chain | You can limit |
|---|---|
| EVM | Contract addresses, function selectors, max value, chain ids, EIP-712 contract and type, message signing. |
| Solana | Programs; token transfers by mint, destination and max or exact amounts; SOL transfers by destination and max. |

For example, a subscription signer can be limited to "USDC to our treasury token account, for exactly 4.99 or 49.99, nothing else".

## Good practice [#good-practice]

- Grant the **smallest scope** that does the job: one network, the signing kinds you need, a value cap.
- Keep grants **short-lived** and re-issue them.
- Store the agent's private key like any secret, and **revoke** the grant the moment you stop the agent.
- Your operators can see each user's grants, with their state, in the Swivy console's user directory.
