Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(eve): set AI_AGENT=eve for sandbox commands (#4659)

Andrew Barba3445e89e736c
diff --git a/.changeset/sandbox-ai-agent-env.md b/.changeset/sandbox-ai-agent-env.md
new file mode 100644
index 000000000..d4383aa16
--- /dev/null
+++ b/.changeset/sandbox-ai-agent-env.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Sandbox commands now run with `AI_AGENT=eve` by default, so agent-aware CLIs such as `vercel` switch to their non-interactive agent mode. Set `AI_AGENT` in the environment's `env` option, or in the `env` of one `run()` or `spawn()` call, to override it.
diff --git a/docs/sandbox/index.mdx b/docs/sandbox/index.mdx
index 29e3e1bf2..37e599731 100644
--- a/docs/sandbox/index.mdx
+++ b/docs/sandbox/index.mdx
@@ -28,6 +28,8 @@ export default defineTool({
Relative paths resolve under `/workspace`. `run()` returns `{ exitCode, stdout, stderr }`; a nonzero exit code does not throw automatically. Use `spawn()` for a long-running process.
+Built-in environments set `AI_AGENT=eve` on every `run()` and `spawn()` call, including the `bash` tool and `prepare`, so agent-aware CLIs such as `vercel` skip interactive prompts. To use a different value, set `AI_AGENT` in the environment's `env` option or pass it in the `env` of one `run()` or `spawn()` call.
+
Pass the configured environment to preserve its specific session capabilities in authored runtime code:
```ts
diff --git a/packages/eve/src/execution/sandbox/bindings/docker-container.ts b/packages/eve/src/execution/sandbox/bindings/docker-container.ts
index 6ea62ca71..0b144293e 100644
--- a/packages/eve/src/execution/sandbox/bindings/docker-container.ts
+++ b/packages/eve/src/execution/sandbox/bindings/docker-container.ts
@@ -3,6 +3,7 @@ import type { DockerCli } from "#execution/sandbox/bindings/docker-cli.js";
import type { ResolvedDockerSandboxOptions } from "#execution/sandbox/bindings/docker-options.js";
import { expectDockerSuccess } from "#execution/sandbox/bindings/docker-utils.js";
import { withDevelopmentSandboxTags } from "#execution/sandbox/development-run.js";
+import { SANDBOX_AGENT_ENV } from "#execution/sandbox/session.js";
import type { DockerSandboxNetworkPolicy } from "#public/sandbox/docker-sandbox.js";
import { WORKSPACE_ROOT } from "#runtime/workspace/types.js";
@@ -37,7 +38,7 @@ export async function startDockerContainer(input: {
for (const [key, value] of Object.entries(withDevelopmentSandboxTags(input.tags) ?? {})) {
args.push("--label", `${DOCKER_SANDBOX_LABEL}.tag.${key}=${value}`);
}
- for (const [key, value] of Object.entries(input.options.env)) {
+ for (const [key, value] of Object.entries({ ...SANDBOX_AGENT_ENV, ...input.options.env })) {
args.push("-e", `${key}=${value}`);
}
if (input.initialNetworkPolicy === "deny-all") {
diff --git a/packages/eve/src/execution/sandbox/bindings/docker.integration.test.ts b/packages/eve/src/execution/sandbox/bindings/docker.integration.test.ts
index d118e7426..7453f3794 100644
--- a/packages/eve/src/execution/sandbox/bindings/docker.integration.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/docker.integration.test.ts
@@ -185,6 +185,26 @@ describe("Docker provider prewarm", () => {
);
});
+ it.each([
+ { env: undefined, expected: "AI_AGENT=eve" },
+ { env: { AI_AGENT: "alice-bot" }, expected: "AI_AGENT=alice-bot" },
+ ])("sets $expected on the container from environment env $env", async ({ env, expected }) => {
+ const appRoot = await createScratchDirectory("eve-docker-sandbox-");
+ const { calls, cli } = createFakeDockerCli((args) =>
+ args[0] === "image" &&
+ args[1] === "inspect" &&
+ String(args.at(-1)).startsWith("eve-sandbox-template:")
+ ? { exitCode: 1, stderr: "No such image" }
+ : undefined,
+ );
+
+ await createEngine({ cli, options: { env } }).prepare({ appRoot, seedFiles: [] });
+
+ const runArgs = findCall(calls, (args) => args[0] === "run")?.args ?? [];
+ expect(runArgs.filter((arg) => arg.startsWith("AI_AGENT="))).toEqual([expected]);
+ expect(runArgs[runArgs.indexOf(expected) - 1]).toBe("-e");
+ });
+
it("builds, seeds, commits, and cleans up when the template image is missing", async () => {
const appRoot = await createScratchDirectory("eve-docker-sandbox-");
const { calls, cli } = createFakeDockerCli((args) => {
diff --git a/packages/eve/src/execution/sandbox/bindings/just-bash-runtime.ts b/packages/eve/src/execution/sandbox/bindings/just-bash-runtime.ts
index f3598f347..58b0f63cf 100644
--- a/packages/eve/src/execution/sandbox/bindings/just-bash-runtime.ts
+++ b/packages/eve/src/execution/sandbox/bindings/just-bash-runtime.ts
@@ -9,7 +9,7 @@ import {
} from "#execution/sandbox/bindings/local-provider-utils.js";
import { adaptMultiplexedCommandToSandboxProcess } from "#execution/sandbox/multiplexed-command.js";
import { shellQuote } from "#execution/sandbox/shell-quote.js";
-import { buildSandboxSession } from "#execution/sandbox/session.js";
+import { buildSandboxSession, SANDBOX_AGENT_ENV } from "#execution/sandbox/session.js";
import type { SandboxProviderHandle, SandboxProviderHost } from "#shared/sandbox-provider.js";
import type { SandboxSession } from "#shared/sandbox-session.js";
import type { JustBashSandboxCreateOptions } from "#public/sandbox/just-bash-sandbox.js";
@@ -174,7 +174,7 @@ export async function createBashSandbox(input: {
args: [wrapped],
cmd: "eval",
detached: true,
- env: options.env,
+ env: { ...SANDBOX_AGENT_ENV, ...options.env },
signal: options.abortSignal,
});
return adaptMultiplexedCommandToSandboxProcess({
diff --git a/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts b/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts
index 55b9dfd7f..d6d35df5c 100644
--- a/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts
@@ -167,12 +167,12 @@ describe("just-bash sandbox file API", () => {
});
const result = await handle.sandbox.run({
- command: 'echo "$DEPLOY_ENV"',
+ command: 'echo "$DEPLOY_ENV $AI_AGENT"',
env: { DEPLOY_ENV: "staging" },
});
expect(result.exitCode).toBe(0);
- expect(result.stdout.trim()).toBe("staging");
+ expect(result.stdout.trim()).toBe("staging eve");
});
it("runs bash tool commands directly because just-bash cannot host background jobs", async () => {
diff --git a/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.test.ts b/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.test.ts
index 02f18ee90..3b5522bea 100644
--- a/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.test.ts
@@ -295,6 +295,43 @@ describe.skipIf(process.platform === "win32")("MicrosandboxVm", () => {
expect(sandbox.detach).toHaveBeenCalledTimes(1);
});
+ it.each([
+ { callEnv: undefined, env: undefined, expected: "eve" },
+ { callEnv: undefined, env: { AI_AGENT: "alice-bot" }, expected: "alice-bot" },
+ { callEnv: { AI_AGENT: "bob-bot" }, env: { AI_AGENT: "alice-bot" }, expected: "bob-bot" },
+ ])("sets AI_AGENT=$expected beneath environment and per-call env", async (row) => {
+ let envs: Record<string, string> | undefined;
+ const builder = {
+ args: () => builder,
+ cwd: () => builder,
+ envs: (value: Record<string, string>) => {
+ envs = value;
+ return builder;
+ },
+ user: () => builder,
+ };
+ const sandbox = {
+ async execStreamWith(_command: string, configure: (value: typeof builder) => unknown) {
+ configure(builder);
+ return createHangingExecHandleAfterExit([{ code: 0, kind: "exited" }]);
+ },
+ };
+ const vm = new MicrosandboxVm(
+ {
+ module: {} as never,
+ options: resolveMicrosandboxOptions({ env: row.env, image: MICROSANDBOX_DEFAULT_IMAGE }),
+ sessionKey: "session-key",
+ },
+ sandbox as never,
+ "sandbox-name",
+ undefined,
+ );
+
+ await vm.spawn({ command: "vercel whoami", env: row.callEnv });
+
+ expect(envs?.AI_AGENT).toBe(row.expected);
+ });
+
it("finishes streamed commands when the exec handle emits an exit event", async () => {
const sandbox = {
async execStreamWith() {
diff --git a/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.ts b/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.ts
index eaff8d4f0..97da22484 100644
--- a/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.ts
+++ b/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.ts
@@ -29,6 +29,7 @@ import {
isEveDevEnvironment,
} from "#internal/application/optional-package-install.js";
import { withDevelopmentSandboxTags } from "#execution/sandbox/development-run.js";
+import { SANDBOX_AGENT_ENV } from "#execution/sandbox/session.js";
import { WORKSPACE_ROOT } from "#runtime/workspace/types.js";
import type { SandboxNetworkPolicy } from "#shared/sandbox-network-policy.js";
import type { SandboxProviderHost } from "#shared/sandbox-provider.js";
@@ -238,6 +239,7 @@ export class MicrosandboxVm {
}
const env = {
+ ...SANDBOX_AGENT_ENV,
...this.#input.options.env,
HOME: MICROSANDBOX_HOME,
...createTransformBrokerEnvironment(createMicrosandboxNetworkPlan(this.#networkPolicy)),
diff --git a/packages/eve/src/execution/sandbox/bindings/vercel.test.ts b/packages/eve/src/execution/sandbox/bindings/vercel.test.ts
index 7423a15e8..831f94824 100644
--- a/packages/eve/src/execution/sandbox/bindings/vercel.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/vercel.test.ts
@@ -1045,7 +1045,7 @@ describe("createVercelSandbox", () => {
);
});
- it("forwards env to runCommand when spawning a process", async () => {
+ it("forwards env with the AI_AGENT default to runCommand when spawning a process", async () => {
const templateSandbox = createMockSandbox({ name: "template" });
const sessionSandbox = createMockSandbox({ name: "session" });
const sandboxModule = {
@@ -1084,12 +1084,12 @@ describe("createVercelSandbox", () => {
expect.objectContaining({
args: ["-lc", "printenv DEPLOY_ENV"],
cmd: "bash",
- env: { DEPLOY_ENV: "staging" },
+ env: { AI_AGENT: "eve", DEPLOY_ENV: "staging" },
}),
);
});
- it("forwards env to runCommand when running a command", async () => {
+ it("lets environment env override the AI_AGENT default when running a command", async () => {
const templateSandbox = createMockSandbox({ name: "template" });
const sessionSandbox = createMockSandbox({ name: "session" });
const sandboxModule = {
@@ -1103,6 +1103,7 @@ describe("createVercelSandbox", () => {
};
const provider = createTestVercelSandbox({
+ createOptions: { env: { AI_AGENT: "alice-bot" } },
loadSandboxModule: async () => sandboxModule as never,
});
@@ -1128,7 +1129,7 @@ describe("createVercelSandbox", () => {
expect.objectContaining({
args: ["-lc", "printenv DEPLOY_ENV"],
cmd: "bash",
- env: { DEPLOY_ENV: "production" },
+ env: { AI_AGENT: "alice-bot", DEPLOY_ENV: "production" },
}),
);
});
diff --git a/packages/eve/src/execution/sandbox/bindings/vercel.ts b/packages/eve/src/execution/sandbox/bindings/vercel.ts
index 0db32484a..93a01f2d2 100644
--- a/packages/eve/src/execution/sandbox/bindings/vercel.ts
+++ b/packages/eve/src/execution/sandbox/bindings/vercel.ts
@@ -35,7 +35,7 @@ import type {
import { WORKSPACE_ROOT } from "#runtime/workspace/types.js";
import { createLoggingSandboxSession } from "#execution/sandbox/logging-session.js";
import { adaptMultiplexedCommandToSandboxProcess } from "#execution/sandbox/multiplexed-command.js";
-import { buildSandboxSession } from "#execution/sandbox/session.js";
+import { buildSandboxSession, SANDBOX_AGENT_ENV } from "#execution/sandbox/session.js";
import { createSandboxProviderIdentity } from "#execution/sandbox/provider-identity.js";
import { streamToBuffer } from "#execution/sandbox/stream-utils.js";
import {
@@ -417,7 +417,7 @@ async function ensureTemplate(input: EnsureTemplateInput): Promise<EnsureTemplat
await applyInitialVercelNetworkPolicy(sandbox, input.createOptions.networkPolicy);
const templateSession = buildSandboxSession(
- createVercelInternalSandboxSession(sandbox),
+ createVercelInternalSandboxSession(sandbox, input.createOptions.env),
createVercelNetworkPolicySetter(sandbox),
);
@@ -571,7 +571,7 @@ function createHandle(input: {
const { sandbox } = input;
return {
sandbox: buildSandboxSession(
- createVercelInternalSandboxSession(sandbox),
+ createVercelInternalSandboxSession(sandbox, input.createOptions.env),
createVercelNetworkPolicySetter(sandbox),
),
async onSandboxDelete(options) {
@@ -595,7 +595,11 @@ function createHandle(input: {
};
}
-function createVercelInternalSandboxSession(sandbox: VercelSandbox): InternalSandboxSession {
+function createVercelInternalSandboxSession(
+ sandbox: VercelSandbox,
+ environmentEnv: Readonly<Record<string, string>> | undefined,
+): InternalSandboxSession {
+ const baseEnv = { ...SANDBOX_AGENT_ENV, ...environmentEnv };
return {
resolvePath: resolveVercelSandboxPath,
async spawn(options: SandboxSpawnOptions): Promise<SandboxProcess> {
@@ -604,7 +608,7 @@ function createVercelInternalSandboxSession(sandbox: VercelSandbox): InternalSan
cmd: "bash",
cwd: options.workingDirectory ?? WORKSPACE_ROOT,
detached: true,
- env: options.env,
+ env: { ...baseEnv, ...options.env },
signal: options.abortSignal,
});
return adaptMultiplexedCommandToSandboxProcess({
diff --git a/packages/eve/src/execution/sandbox/session.ts b/packages/eve/src/execution/sandbox/session.ts
index e04d3211b..3f29a0eb0 100644
--- a/packages/eve/src/execution/sandbox/session.ts
+++ b/packages/eve/src/execution/sandbox/session.ts
@@ -20,6 +20,13 @@ import { bufferToStream, streamToBuffer } from "./stream-utils.js";
export type { InternalSandboxSession };
+/**
+ * Tells agent-aware CLIs (such as `vercel`) that an automated agent runs
+ * the command, so they skip interactive prompts. Built-in providers apply it
+ * beneath environment-level and per-call env so authors can override it.
+ */
+export const SANDBOX_AGENT_ENV: Readonly<Record<string, string>> = { AI_AGENT: "eve" };
+
/**
* Builds a public {@link SandboxSession} from provider-specific primitives.
*