> ## Documentation Index
> Fetch the complete documentation index at: https://agentrein.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Execution Methods

> How AgentRein intercepts and protects your API calls.

## wrap()

The single execution primitive in AgentRein. Pass any API client (or a specific
sub-resource object) and AgentRein intercepts every method call automatically.

<CodeGroup>
  ```ts TypeScript theme={null}
  import { AgentRein } from 'agentrein';
  import { Octokit } from '@octokit/rest';

  const agentrein = new AgentRein({ apiKey: '...' });
  const octokit = new Octokit({ auth: '...' });

  const agentOctokit = agentrein.wrap(octokit, session, { connector: 'github' });

  // Use exactly as before — rollback is automatic on any failure
  await agentOctokit.issues.create({ owner: 'my-org', repo: 'my-repo', title: 'Task' });
  ```

  ```python Python theme={null}
  from agentrein import AgentRein
  from github import Github

  agentrein = AgentRein(api_key="...")
  gh = Github(auth="...")
  repo = gh.get_repo("my-org/my-repo")

  agent_repo = agentrein.wrap(repo, session, connector="github")

  # Use exactly as before — rollback is automatic on any failure
  agent_repo.create_issue(title="Task")
  ```
</CodeGroup>

## Approval Gates with wrap()

Pass `requiresApproval` (Python: `requires_approval`) with a list of method paths
that need human sign-off before executing.

<CodeGroup>
  ```ts TypeScript theme={null}
  const agentStripe = agentrein.wrap(stripe, session, {
      connector: 'stripe',
      requiresApproval: ['subscriptions.cancel', 'invoices.del'],
      pollIntervalMs: 2000,
      timeoutMs: 300000,
  });

  // Executes immediately — no approval needed
  await agentStripe.invoices.create({ customer: 'cus_123', amount: 500 });

  // Pauses here until a reviewer approves from the dashboard
  await agentStripe.subscriptions.cancel({ id: 'sub_123' });
  ```

  ```python Python theme={null}
  agent_stripe = agentrein.wrap(
      stripe_client, session,
      connector="stripe",
      requires_approval=["subscriptions.cancel", "invoices.delete"],
      poll_interval_ms=2000,
      timeout_ms=300000,
  )

  # Executes immediately — no approval needed
  agent_stripe.invoices.create(customer="cus_123", amount=500)

  # Pauses here until a reviewer approves from the dashboard
  agent_stripe.subscriptions.cancel(id="sub_123")
  ```
</CodeGroup>

If rejected, `ApprovalRejectedError` is thrown/raised and the session is
automatically rolled back.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.