# What is the easiest way to let an AI agent create and run a scheduled job?

> Connect an AI agent to GearTrain over MCP, then ask it to create the job. The agent can write the script, create the job, run it once, read the console, and fix failures. You approve the scopes, and scheduled runs continue without the agent.

## The problem

A coding agent can write the script, but writing the script is only part of the job. The code still needs a runtime, a schedule, files that survive between runs, secrets, and a place to read the console when something fails.

Without a runtime, the agent hands you code and a list of setup steps. You create the infrastructure, paste the code, configure the schedule, add the credentials, and return to the agent only when the first run fails. The agent wrote the easy part; you still did the deployment.

## The usual options

| Option | Good fit | The friction |
| --- | --- | --- |
| Copy the code to a server | You already have a server and want control | You handle setup, files, secrets, scheduling, logs, and updates |
| A CI workflow | The job belongs next to a repository | Schedules are tied to CI runners and repository configuration |
| A cloud function | You want managed execution | You still set up the account, permissions, packaging, and logs |
| Local cron | The script runs on your own machine | The machine must stay on, and secrets and history stay local |
| An agent with shell access | The agent operates a machine you control | You grant broad access and own the environment and cleanup |

The missing piece is not code generation. It is a safe place for the code to run, with the supporting state and controls already present.

## How GearTrain solves it

GearTrain is a runtime for exactly this handoff:

- Connect your agent to the remote MCP server with OAuth.
- Approve the scopes the agent needs.
- Ask the agent to create the script and job.
- Let it run the job and read the console.
- Let it fix the script and run again.
- Leave the schedule running after the agent disconnects.

The agent can create and update jobs, run them, read the console, browse and edit files, and rename or enable and disable existing webhook endpoints within the approved scopes. Secret values never reach the agent. It can use a secret by name, but the value stays in the web app.

The agent acts when you ask it to. Scheduled runs do not depend on the agent being connected.

## What it looks like in practice

```text
Create a job called Weekly report that runs /reports/weekly.js every Monday at
8. Run it once, read the console, and fix anything that fails.
```

The agent creates the script and job, runs it once, and reports the result. You approve the scopes at connection time. If you want to limit the agent later, revoke it under Settings > Authorized Apps.

## When GearTrain is not the right fit

- Your agent cannot connect to a remote MCP server.
- The job needs a long-running process or a full browser.
- The work needs packages or heavy compute.

For those cases, the agent may still write the code, but you need a different runtime.

## Related solutions

- [How do I run a script on a schedule without running a server?](https://geartrain.dev/solutions/run-a-script-on-a-schedule-without-a-server)
- [How do I receive a webhook without running a server?](https://geartrain.dev/solutions/receive-a-webhook-without-running-a-server)
- [When is code simpler than a visual automation builder?](https://geartrain.dev/solutions/code-vs-visual-builder)

## Documentation

- [Connect an AI Agent](https://docs.geartrain.dev/guide/mcp)
- [Writing Jobs](https://docs.geartrain.dev/guide/writing-jobs)
- [Secrets and Environment Variables](https://docs.geartrain.dev/guide/secrets-and-env)

## Start

- [Start free](https://app.geartrain.dev/signup)
