Quickstart

Deploy your first agent in 5 minutes with sandboxes, code execution, browser automation, and email — a complete agent loop.

Prerequisites

  • A Transactional account with an API key
  • Node.js 18+ installed

Install the SDK

npm install @usetransactional/node

Initialize the Client

import Transactional from '@usetransactional/node';
 
const tx = new Transactional({
  apiKey: process.env.TRANSACTIONAL_API_KEY,
});

Step 1: Create a Sandbox

Spin up an isolated execution environment with a Python runtime:

const sandbox = await tx.sandboxes.create({
  runtime: 'python-3.12',
  timeout: 300, // 5 minutes
});
 
console.log(`Sandbox ready: ${sandbox.id}`);

Step 2: Run Code in the Sandbox

Run a script inside the sandbox to process some data:

const result = await tx.sandboxes.run(sandbox.id, {
  command: 'python3',
  args: ['-c', `
import json
 
data = {"products": ["Widget A", "Widget B", "Widget C"]}
prices = [29.99, 49.99, 19.99]
 
report = []
for name, price in zip(data["products"], prices):
    report.append({"name": name, "price": price, "formatted": f"${price:.2f}"})
 
print(json.dumps(report, indent=2))
  `],
});
 
console.log('Script output:', result.stdout);

Step 3: Browse a Web Page

Open a headless browser to gather information:

const session = await tx.browsers.create();
 
await tx.browsers.navigate(session.id, {
  url: 'https://example.com/pricing',
});
 
const data = await tx.browsers.extractText(session.id, {
  selector: '.pricing-table',
});
 
console.log('Extracted pricing:', data.text);
 
await tx.browsers.close(session.id);

Step 4: Transform Data with Code Execution

Use code execution for a fast, stateless computation:

const transformed = await tx.code.run({
  language: 'javascript',
  code: `
    const data = JSON.parse(process.argv[1]);
    const summary = data.map(p => p.name + ': ' + p.formatted).join('\\n');
    console.log(summary);
  `,
  args: [result.stdout],
});
 
console.log('Summary:', transformed.stdout);

Step 5: Send the Results via Email

Complete the agent loop by sending results to a user:

await tx.emails.send({
  from: 'agent@yourdomain.com',
  to: 'user@example.com',
  subject: 'Agent Report: Product Pricing Analysis',
  html: '<h2>Pricing Analysis Complete</h2><pre>' + transformed.stdout + '</pre>',
});
 
console.log('Report sent!');

Step 6: Clean Up

Destroy the sandbox when done:

await tx.sandboxes.destroy(sandbox.id);

Full Example

Here is the complete agent loop in one script:

import Transactional from '@usetransactional/node';
 
const tx = new Transactional({
  apiKey: process.env.TRANSACTIONAL_API_KEY,
});
 
async function runAgent() {
  // 1. Create sandbox
  const sandbox = await tx.sandboxes.create({ runtime: 'python-3.12' });
 
  // 2. Run analysis script
  const analysis = await tx.sandboxes.run(sandbox.id, {
    command: 'python3',
    args: ['-c', 'print("Analysis complete: 3 products processed")'],
  });
 
  // 3. Browse for additional context
  const session = await tx.browsers.create();
  await tx.browsers.navigate(session.id, { url: 'https://example.com' });
  const pageData = await tx.browsers.extractText(session.id, { selector: 'body' });
  await tx.browsers.close(session.id);
 
  // 4. Transform results
  const summary = await tx.code.run({
    language: 'javascript',
    code: 'console.log("Agent completed at: " + new Date().toISOString());',
  });
 
  // 5. Send report
  await tx.emails.send({
    from: 'agent@yourdomain.com',
    to: 'user@example.com',
    subject: 'Agent Report',
    text: analysis.stdout + '\n' + summary.stdout,
  });
 
  // 6. Clean up
  await tx.sandboxes.destroy(sandbox.id);
 
  console.log('Agent loop complete.');
}
 
runAgent();

Next Steps