Build
Common workflows
Practical patterns for CI jobs, isolated agent work, and parallel sandboxes.
On this page
Run a CI job in a sandbox
Start a clean environment for a job, collect its output, and remove it when the job finishes.
Use one sandbox per job when builds need a clean environment or when repository code should not run on your application host. Pick a template that already contains the language runtime and system tools your project needs; install only the project dependencies during the job.
Create a server-side API key with sandbox create, read, and delete permissions. Keep it in your CI secret store. Set ZEISH_TEMPLATE_ID to a template visible to the key's organization and use a unique run name or label to trace jobs back to your CI run.
The job below waits for the runtime, checks out a public repository, runs the project command, prints the result, and requests deletion in a finally block. Replace the repository URL and command with your project values. For a private repository, provide short-lived Git credentials through your secret manager. Persist artifacts before cleanup: files written only inside a sandbox do not become artifacts in your CI system automatically.
If the job can be retried after a network failure, give the create request a stable idempotency key for that CI attempt. Do not reuse one key for a different job. For a command that outlives your CI request timeout, start it in the background and collect its result through your application workflow.
1import { createZeishSandboxClient } from "@zeish/computesdk-provider";23const client = createZeishSandboxClient({4 apiKey: process.env.ZEISH_API_KEY!,5 baseUrl: "https://api.zei.sh/api/v1",6 defaultTemplateId: process.env.ZEISH_TEMPLATE_ID!,7});89const sandbox = await client.create({10 name: "ci-" + process.env.CI_RUN_ID,11 labels: { source: "ci", run: process.env.CI_RUN_ID ?? "local" },12});1314try {15 await sandbox.waitForAccess();16 const checkout = await sandbox.run(17 "git clone https://github.com/acme/example.git /workspace/repo",18 );19 if (checkout.exitCode !== 0) throw new Error("Repository checkout failed");2021 const result = await sandbox.run("npm ci && npm test", {22 workingDirectory: "/workspace/repo",23 timeoutMs: 10 * 60 * 1000,24 });25 process.stdout.write(result.stdout);26 process.stderr.write(result.stderr);27 if (result.exitCode !== 0) throw new Error("CI command failed");28} finally {29 await sandbox.destroy();30}Give an agent an isolated workspace
Prepare a sandbox with your project, let your own agent work in it, and retrieve the result.
A sandbox is the agent's workspace. Your application remains the orchestrator: it creates the sandbox, supplies only the credentials needed for this task, starts the agent process, and decides what to do with the resulting changes.
Choose a template with the agent's runtime dependencies already installed. For a public repository, clone it into the workspace before starting the agent. For a private repository, arrange Git credentials through your secret manager and inject them only for the task; do not bake long-lived credentials into a reusable template.
Use a unique sandbox for each task when work must be isolated. Keep task inputs and outputs in a known directory, inspect the exit status, and export a patch or other artifact to your application before deleting the sandbox. A sandbox is not a substitute for reviewing agent-generated code.
The example prepares a public repository and runs a placeholder agent command. Replace that command with the agent and invocation your product supports. Provide model credentials through an approved secret flow rather than embedding them in the command string.
1import { createZeishSandboxClient } from "@zeish/computesdk-provider";23const client = createZeishSandboxClient({4 apiKey: process.env.ZEISH_API_KEY!,5 baseUrl: "https://api.zei.sh/api/v1",6 defaultTemplateId: process.env.ZEISH_TEMPLATE_ID!,7});89const sandbox = await client.create({10 name: "task-" + task.id,11 labels: { taskId: task.id },12});1314try {15 await sandbox.waitForAccess();16 const clone = await sandbox.run(17 "git clone https://github.com/acme/example.git /workspace/repo",18 );19 if (clone.exitCode !== 0) throw new Error("Repository clone failed");2021 const result = await sandbox.run("your-agent-command --workdir /workspace/repo", {22 workingDirectory: "/workspace/repo",23 timeoutMs: 15 * 60 * 1000,24 });2526 if (result.exitCode !== 0) throw new Error("Agent task failed");27 const patch = await sandbox.run("git diff --binary", {28 workingDirectory: "/workspace/repo",29 });30 process.stdout.write(patch.stdout);31} finally {32 await sandbox.destroy();33}Run independent tasks in parallel
Use a prepared sandbox as a starting point and create a separate workspace for each worker.
Parallel work is easiest when every worker starts from the same prepared project state and writes to its own sandbox. Prepare dependencies once in a source sandbox, then clone that sandbox for each task. Keep the source unchanged after preparing it so each worker starts from the same baseline.
Create and track each clone independently. Give it a task-specific name and label, wait until it is ready, and capture its output or patch before cleanup. Limit concurrency to the capacity and organization limits available to your account; handle a failed clone as one task failure instead of restarting the whole batch.
Use this flow when tasks can be evaluated independently. If multiple workers modify the same branch or shared volume, add an explicit merge and conflict-resolution step in your orchestrator.
1# Prepare the source sandbox once, then clone it for each independent task.2zeishctl sandboxes clone SOURCE_SANDBOX_ID --name worker-13zeishctl sandboxes clone SOURCE_SANDBOX_ID --name worker-24zeishctl sandboxes list