All skills
apify avatar

/apify-actorization

@16bac29 official
by apifyapify/agent-skills2.4k stars
259

Convert existing projects into Apify Actors - serverless cloud programs. Actorize JavaScript/TypeScript (SDK with Actor.init/exit), Python (async context manager), or any language (CLI wrapper). Use when migrating code to Apify, wrapping CLI tools as Actors, or adding Actor SDK to existing projects.

Use this Skill: https://skilld.dev/gh/apify/agent-skills/apify-actorization

This session only. Nothing lands on disk.

referencesjs-ts-actorization.md

≈606 tokens on demand. Your agent reads this file only when SKILL.md points to it.

JavaScript/TypeScript Actorization

Install the Apify SDK

npm install apify

Wrap main code with Actor lifecycle

import { Actor } from 'apify';

// Initialize connection to Apify platform
await Actor.init();

// ============================================
// Your existing code goes here
// ============================================

// Example: Get input from Apify Console or API
const input = await Actor.getInput();
console.log('Input:', input);

// Example: Your crawler or processing logic
// const crawler = new PlaywrightCrawler({ ... });
// await crawler.run([input.startUrl]);

// Example: Push results to dataset
// await Actor.pushData({ result: 'data' });

// ============================================
// End of your code
// ============================================

// Graceful shutdown
await Actor.exit();

Key points

  • Actor.init() configures storage to use Apify API when running on platform
  • Actor.exit() handles graceful shutdown and cleanup
  • Both calls must be awaited
  • Local execution remains unchanged - the SDK automatically detects the environment

Crawlee projects

Crawlee projects require minimal changes - just wrap with Actor lifecycle:

import { Actor } from 'apify';
import { PlaywrightCrawler } from 'crawlee';

await Actor.init();

// Get and validate input
const input = await Actor.getInput();
const {
    startUrl = 'https://example.com',
    maxItems = 100,
} = input ?? {};

let itemCount = 0;

const crawler = new PlaywrightCrawler({
    requestHandler: async ({ page, request, pushData }) => {
        if (itemCount >= maxItems) return;

        const title = await page.title();
        await pushData({ url: request.url, title });
        itemCount++;
    },
});

await crawler.run([startUrl]);

await Actor.exit();

Express/HTTP servers

For web servers, use standby mode in actor.json:

{
    "actorSpecification": 1,
    "name": "my-api",
    "usesStandbyMode": true
}

Then implement readiness probe. See standby-mode.md.

Batch processing scripts

import { Actor } from 'apify';

await Actor.init();

const input = await Actor.getInput();
const items = input.items || [];

for (const item of items) {
    const result = processItem(item);
    await Actor.pushData(result);
}

await Actor.exit();

Source: SKILL.md on GitHub

1 warning1d5 checks · Risk SAFE
  • Gen Agent Trust Hub1d

    The skill provides templates and instructions for building Apify Actors. It includes security best practices for handling secrets and untrusted data. One example uses a remote script execution pattern for tool installation in a Dockerfile, which is a potential security risk.

  • Socket1d

    No alerts

  • Snyk1d

    Risk: LOW · No issues

  • Runlayer7mo

    2/5 files flagged

  • ZeroLeaks5mo

    1 finding · Score: 82/100

Signed by skilld at 16bac29. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 2 weeks ago

README badge

README badge for apify/agent-skills/apify-actorization