Browse docs
On this page

Scripted Inputs

Run a Python or Bash collector on a schedule without operating another service.

Scripted Inputs run a short Python or Bash program for you on a UTC cron schedule. Use one when a service has an API or command-line interface but no built-in connector, and you do not want to operate a separate collector.

Each run starts in a fresh, read-only container with CPU, memory, process, time, output, and filesystem limits. A script can reach any public internet address. Private, loopback, link local, and reserved addresses are always refused, including the cloud instance metadata endpoint, so a script cannot reach anything inside the platform's own network. Events enter the same ingestion pipeline as every other source.

Create an input

  1. Open Connect Your Data (or choose + Add a source on Data Sources) and choose Scripted input.
  2. On Details, name the input and choose Python or Bash.
  3. On Schedule & setup, enter a five-field cron expression, add any Extra Dependencies, and add only the secrets this script needs. Schedules use UTC.
  4. On Script, write the script in the editor. Use full-screen mode for longer scripts, and run a dry run to check it before you save.
  5. On Review & save, check the sandbox limits, then choose Create scripted input.

To change an input later, open it from Data Sources and choose Edit, then Save changes. Turn off Enabled to keep its configuration without allowing scheduled runs. Run opens a panel where Run now runs the script once, either as a dry run that ingests nothing or for real through the same worker and sandbox used by the schedule.

How a script sends events

A script sends events by writing JSON to standard output. There is nothing to register and no endpoint to call. You do not need an SDK: print in Python and echo, printf or jq in Bash all work, as long as each event is written the way described here.

The rules the runtime applies:

  • One event per line. When the script exits, its standard output is split into lines and each non-blank line is read on its own. A line that holds one JSON object becomes one event with those fields.
  • Plain text is ingested too. A line that is not a JSON object, such as print("done") or echo "starting", becomes an event whose message is the line as printed, just as if the script had written {"message": "done"}. Use JSON when you want named fields you can filter and chart on.
  • Standard error is for diagnostics. Anything written to stderr is shown in the run's execution history and never becomes an event. Use it for progress and debugging output.
  • Events are read after the run. Output is collected while the script runs and ingested once it exits, so events appear in search when the run finishes. Events printed before a failure or a timeout are still ingested.
  • Output is capped. Roughly the first 8 MB of stdout from a run is read. Anything after that is dropped, so a run that needs to send more should send less per run and run more often.

Minimal Python example

Python
import json

print(json.dumps({"message": "Nightly import finished", "level": "info", "rows": 42}))

json.dumps writes the whole object on one line by default. Pretty printed JSON, from indent= or jq without -c, also works: an object spread across several lines is put back together into one event. One object per line is still the simplest and smallest output.

Minimal Bash example

Shell
#!/usr/bin/env bash
set -euo pipefail

echo '{"message":"Nightly import finished","level":"info","rows":42}'

When an event contains values from variables or command output, build it with jq rather than by joining strings, so quotes, backslashes and newlines are escaped correctly. -n starts from nothing and -c keeps the result on one line:

Shell
#!/usr/bin/env bash
set -euo pipefail

host="$(hostname)"
jq -nc --arg host "$host" --argjson rows 42 \
  '{message: "Nightly import finished", level: "info", host: $host, rows: $rows}'

To turn every line of a command's text output into its own event, let jq wrap each raw line:

Shell
df -h | jq -Rc '{message: ., source: "df"}'

Multi-line events

An event is always one line of output, but its values can contain line breaks. A stack trace or a command's full report belongs inside a string value, where JSON writes each line break as \n. The stored event keeps the original line breaks.

Python
import json
import traceback

try:
    raise RuntimeError("upstream returned 503")
except RuntimeError:
    print(json.dumps({
        "message": "Import failed",
        "level": "error",
        "stack": traceback.format_exc(),
    }))
Shell
report="$(df -h)"
jq -nc --arg report "$report" '{message: "Disk usage", report: $report}'

Writing the trace or report directly to stdout instead would produce one separate plain text event per line of output.

Timestamps

An event's time is read from the first of these keys that is present: timestamp, time, ts, @timestamp, date, eventTime, then observedTimestamp. The value can be:

  • An ISO 8601 string, such as 2026-10-14T09:30:00Z or 2026-10-14T09:30:00.123+01:00. Always include a Z or an offset, because a time without one is not reliably read as UTC.
  • A Unix epoch number in seconds, milliseconds or nanoseconds, such as 1792056600. A number written as a string also works.

An event with no timestamp key, or with a value that cannot be read, is stamped with the time the run started, so every such event from one run shares the same time. A time before the year 2000, or more than an hour in the future, is treated the same way. The key that supplied the time is stored as the event's timestamp, not repeated as a field.

Python
import json
from datetime import datetime, timezone

print(json.dumps({
    "timestamp": datetime.now(timezone.utc).isoformat(),
    "message": "Heartbeat",
}))
Shell
jq -nc --arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" '{timestamp: $ts, message: "Heartbeat"}'

Structured fields

Every key in the object is stored as a searchable field under its own name. message, level and service are conventional names, stored like any other field.

  • Nested objects become dotted field names, so {"http": {"status": 503}} is searchable as http.status. The same applies to a fields object: {"fields": {"region": "eu"}} is stored as fields.region. Put keys at the top level if you want them without a prefix.
  • Arrays are stored as JSON text in a single field rather than split into one field per item.
  • Numbers and booleans are stored as their text form and are still searchable.
  • key=value text inside message, msg or body is also turned into fields, so {"message": "app=billing payment failed"} is searchable by app. A key the object already sets is never replaced.
  • An event keeps at most 250 fields.

Exit codes

The exit code decides what happens to the schedule. Events already printed are ingested whichever code the script exits with.

  • 0 means the run succeeded.
  • 1 means the run failed for a reason that may pass, such as an upstream outage. The run is recorded as failed and the schedule carries on. An uncaught Python exception exits with 1.
  • 3 is reserved for sandbox violations and suspends the input, so do not use it for your own errors.
  • Any other code, including 2, means the script needs fixing. The run is recorded as failed, the input is marked as needing attention, and scheduled runs stop until it is fixed. With set -e, a failing command's own exit code is used, so a curl -f error ends the run this way.

Python helpers

The sandbox includes logs_input_sdk. It is optional: send_event does exactly what print(json.dumps(event), flush=True) does, and get_secret reads only a secret assigned in the wizard, raising an error for any other name.

Python
from logs_input_sdk import send_event

send_event({
    "message": "Hello world",
    "level": "info",
    "service": "daily-import",
})
Python
from logs_input_sdk import get_secret, send_event
import json
import urllib.request

token = get_secret("API_TOKEN")
request = urllib.request.Request(
    "https://api.example.com/events",
    headers={"Authorization": f"Bearer {token}"},
)
with urllib.request.urlopen(request, timeout=30) as response:
    payload = json.load(response)

for item in payload["events"]:
    send_event({
        "timestamp": item["created_at"],
        "message": item["message"],
        "fields": item,
    })

current_input() returns the current input's id and name. current_execution() returns the run id. Neither helper makes a network request.

Python packages

Every Python input can import these without any setup:

  • The Python 3.12 standard library.
  • boto3, the AWS SDK for Python.
  • requests, for HTTP calls.
  • logs_input_sdk, the helpers above.

If a script needs something else, add it under Extra Dependencies, one package per entry. Each entry can be written in one of two ways:

  • A package name, such as tenacity. Every run installs the latest version that is compatible with Python 3.12, so a new release of the package reaches your script on its next run.
  • A package name pinned to one exact version, such as tenacity==9.1.2. Every run installs that version, so the script keeps running the same code until you change the pin. Pin a package when an unexpected upgrade would break the script.

Extras work in both forms, as in requests[socks] or requests[socks]==2.32.3. Version ranges such as tenacity>=9, URLs and file paths are not accepted, and each package can be listed once.

Extra dependencies are installed fresh at the start of every run, so each run needs network access to the public package index and takes a few seconds longer to start.

Only packages written in pure Python work. The sandbox cannot load compiled code, so a package that ships a compiled extension installs and then fails to import. numpy, pandas and psycopg2 are the common examples. Bash inputs cannot install packages.

Bash

Assigned secrets are environment variables with the names shown in the wizard. The Bash image includes curl, jq, openssl, and coreutils, and the output rules above apply unchanged: one JSON object per stdout line.

Shell
#!/usr/bin/env bash
set -euo pipefail

curl -sf \
  -H "Authorization: Bearer $API_TOKEN" \
  https://api.example.com/events |
  jq -c '.events[] | {timestamp: .created_at, message, level: (.level // "info"), fields: .}'

jq -c writes each object on its own line. Without -c, jq pretty prints across several lines and no events are created.

Never print a secret. Known assigned values are redacted from captured output and emitted events as a final safeguard, but redaction is not a substitute for keeping credentials out of output.

Secrets

Each secret belongs to one Scripted Input and reaches its sandbox as an environment variable. Values are encrypted when you save the input and are never shown again. To change a value, delete the secret and add it again. Deleting the input deletes its secrets with it. If several inputs use the same credential, add it to each one.

Execution history and troubleshooting

Open a Scripted Input to see start and finish time, duration, status, exit code, emitted-event count, and redacted stdout and stderr. Output is capped, so use the emitted events for data rather than treating stdout history as an archive.

  • Failed commonly means invalid Python or Bash, a missing command, or an exception. Inspect stderr, choose Edit to fix the script, and dry-run it before you save.
  • Sandbox violation means a timeout, resource limit, or refused network request. A refused request went to a private or internal address. Point the script at the service's public address instead.
  • No events means the program exited without writing anything to stdout. Check that output is not going to stderr instead.
  • Many tiny events such as { and } means an object printed across several lines was not valid JSON, so its lines were ingested one at a time as plain text. Common causes are Python's pprint, which uses single quotes, and trailing commas. Use json.dumps instead.
  • Secret is not assigned means get_secret or the Bash environment name does not exactly match the name of a secret added to this input.