MCPcopy Create free account
hub / github.com/vercel/examples / runCommand

Function runCommand

apps/vibe-coding-platform/ai/tools/run-command.ts:13–204  ·  view source on GitHub ↗
({ writer }: Params)

Source from the content-addressed store, hash-verified

11}
12
13export const runCommand = ({ writer }: Params) =>
14 tool({
15 description,
16 inputSchema: z.object({
17 sandboxId: z
18 .string()
19 .describe('The ID of the Vercel Sandbox to run the command in'),
20 command: z
21 .string()
22 .describe(
23 "The base command to run (e.g., 'npm', 'node', 'python', 'ls', 'cat'). Do NOT include arguments here. IMPORTANT: Each command runs independently in a fresh shell session - there is no persistent state between commands. You cannot use 'cd' to change directories for subsequent commands."
24 ),
25 args: z
26 .array(z.string())
27 .optional()
28 .describe(
29 "Array of arguments for the command. Each argument should be a separate string (e.g., ['install', '--verbose'] for npm install --verbose, or ['src/index.js'] to run a file, or ['-la', './src'] to list files). IMPORTANT: Use relative paths (e.g., 'src/file.js') or absolute paths instead of trying to change directories with 'cd' first, since each command runs in a fresh shell session."
30 ),
31 sudo: z
32 .boolean()
33 .optional()
34 .describe('Whether to run the command with sudo'),
35 wait: z
36 .boolean()
37 .describe(
38 'Whether to wait for the command to finish before returning. If true, the command will block until it completes, and you will receive its output.'
39 ),
40 }),
41 execute: async (
42 { sandboxId, command, sudo, wait, args = [] },
43 { toolCallId }
44 ) => {
45 writer.write({
46 id: toolCallId,
47 type: 'data-run-command',
48 data: { sandboxId, command, args, status: 'executing' },
49 })
50
51 let sandbox: Sandbox | null = null
52
53 try {
54 sandbox = await Sandbox.get({ sandboxId })
55 } catch (error) {
56 const richError = getRichError({
57 action: 'get sandbox by id',
58 args: { sandboxId },
59 error,
60 })
61
62 writer.write({
63 id: toolCallId,
64 type: 'data-run-command',
65 data: {
66 sandboxId,
67 command,
68 args,
69 error: richError.error,
70 status: 'error',

Callers 1

toolsFunction · 0.90

Calls 2

getRichErrorFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected