Register, inspect, test, or remove scripts that run every time this sandbox starts, such as reinstalling project dependencies onto local disk after a sandbox rebuild. Use when dependencies or other local state must come back automatically, or when the user asks what runs at sandbox startup. Not for inspecting, upgrading, or restarting the sandbox itself (use sandbox-manager) or for clock-based schedules (use using-cron).
100%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Medium
Suggest reviewing before use
A startup task is a shell script stored in .workspace/.magic/startup/<task_id>.md. After every sandbox start, all enabled tasks run once, one after another, in the background.
| Situation | Use |
|---|---|
| Dependencies or other local state must come back after a sandbox rebuild | This skill |
| Run something at a time of day or on an interval | using-cron |
| Inspect, upgrade, or restart the sandbox itself | sandbox-manager |
Check the Runtime Environment section in the system prompt. In a cloud sandbox, a rebuild empties local disk, so startup tasks are what bring dependencies back. On a local machine, dependencies are not lost; do not suggest a startup task unless the user asks for one. If they do, it runs every time the service starts.
Tell the user that the script will run automatically every time the sandbox starts, and show the script. Pass confirmed: True only after the user agrees. Creating a task, changing its script, and enabling it all require this confirmation; without it the tool returns confirmation_required.
After a rebuild, dependency directories are empty, not missing. Never use "the directory exists" to decide that dependencies are installed. Use the package manager's own idempotent install:
npm installpnpm install --frozen-lockfile[ -x .venv/bin/python ] || python3 -m venv .venv
.venv/bin/pip install -r requirements.txtuv synccomposer installScripts must not wait for input. Set workdir to the project directory relative to .workspace instead of starting the script with cd.
shell_await.All tools are called through Code Mode and return a readable result.content.
Register a task, then test it right away:
run_sdk_snippet(python_code="""
from sdk.tool import tool
result = tool.call("startup_task_create", {
"name": "my-app deps",
"workdir": "my-app",
"script": "npm install",
"confirmed": True,
})
print(result.content)
if result.ok:
run = tool.call("startup_task_run", {"task_id": result.data["task_id"]})
print(run.content)
""")If the run moved to the background, wait for it with the shell_await call given in run.content until it finishes, and confirm it succeeded.
Other operations:
run_sdk_snippet(python_code="""
from sdk.tool import tool
print(tool.call("startup_task_list", {}).content)
print(tool.call("startup_task_update", {"task_id": "my-app-deps", "timeout_seconds": 1800}).content)
print(tool.call("startup_task_delete", {"task_id": "my-app-deps"}).content)
""")startup_task_update changes only the fields you pass. Changing script or passing enabled: True also requires confirmed: True.
startup_task_list reports how each task ran after this sandbox started:
| Status | What to do |
|---|---|
| Running | Wait with shell_await on its background task ID, then retry your command |
| Succeeded | Nothing |
| Failed | Read the output or log, fix the script or install manually, and tell the user |
| Stopped after timeout | Read the log; raise timeout_seconds only if the install was still progressing |
| Skipped, disabled | Enable it only if the user wants it |
| Skipped, confirmed in a different project | Ask the user again, then call startup_task_update with enabled: True and confirmed: True |
| Not run yet | The startup round has not reached it, or it was never run in this session |
dtyq/magic
0f1432c
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.